Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
未找到C#反射异常方法_C#_Reflection_Dynamics Crm 2011 - Fatal编程技术网

未找到C#反射异常方法

未找到C#反射异常方法,c#,reflection,dynamics-crm-2011,C#,Reflection,Dynamics Crm 2011,您好,我正在开发CRM 2011插件,我有一个反射类型的问题。我已经生成了Entities类,我知道属性存在于类型中,但当我试图获取它的值时,我得到了一个异常,即找不到方法。最愚蠢的是,它在我的机器上工作得很好,但在客户机上却不工作 这是我的代码(我需要从实体中获取所有选项集并对其执行操作): public override void MyExecute() { var fse=TargetEntity.ToEntity(); 类型EquipmentType=fse.GetType(); Tra

您好,我正在开发CRM 2011插件,我有一个反射类型的问题。我已经生成了Entities类,我知道属性存在于类型中,但当我试图获取它的值时,我得到了一个异常,即找不到方法。最愚蠢的是,它在我的机器上工作得很好,但在客户机上却不工作

这是我的代码(我需要从实体中获取所有选项集并对其执行操作):

public override void MyExecute()
{
var fse=TargetEntity.ToEntity();
类型EquipmentType=fse.GetType();
TracingService.Trace(“FSE对象类型:{0}”,EquipmentType.FullName);
IEnumerable optionSetsProperties=EquipmentType.GetProperties()
.Where(x=>x.PropertyType==typeof(OptionSetValue)).ToList();//我从对象类型获取此属性,因此它必须存在。
foreach(期权集合属性中的var期权集合属性)
{   
TracingService.Trace(“解析属性{0}上的ResourceGroup”,optionSetsProperty.Name);
ResolveResourceGroupBySkill(选项SetsProperty,fse);
TracingService.Trace(“Resoloving ResourceGroup finished”);
}
}
私有void ResolveResourceGroupBySkill(属性信息选项集合属性,设备fse)
{
尝试
{
TracingService.Trace(“尝试获取:{0}”,optionSetsProperty.Name)的值;
OptionSetValue skillLevel=(OptionSetValue)optionSetsProperty.GetValue(fse);
TracingService.Trace(“值等于:{0}”,skillLevel);
}
捕获(例外情况除外)
{
TracingService.Trace(“发生错误:{0}”,例如Message);
异常内部=ex;
while(内部!=null)
{
TracingService.Trace(内部消息);
inner=inner.InnerException;
}
抛出新的InvalidOperationException(String.Format(“无法从属性{0}获取技能级别的值”,optionSetsProperty.Name),ex);
}
}
以下是日志详细信息:

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Method not found: 'System.Object System.Reflection.PropertyInfo.GetValue(System.Object)'.Detail: 
<OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">
  <ErrorCode>-2147220891</ErrorCode>
  <ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
    <KeyValuePairOfstringanyType>
      <d2p1:key>OperationStatus</d2p1:key>
      <d2p1:value xmlns:d4p1="http://www.w3.org/2001/XMLSchema" i:type="d4p1:string">0</d2p1:value>
    </KeyValuePairOfstringanyType>
  </ErrorDetails>
  <Message>Method not found: 'System.Object System.Reflection.PropertyInfo.GetValue(System.Object)'.</Message>
  <Timestamp>2014-09-11T12:58:09.2941554Z</Timestamp>
  <InnerFault i:nil="true" />
  <TraceText>

[OC.CSSFieldService: OC.CSSFieldService.ServiceActivity.MyPlugin]
[424ad2a7-ea29-e411-be7f-00155d0aa109: OC.CSSFieldService.ServiceActivity.MyPlugin: Create of equipment]
FSE object type: OC.Data.Equipment
Resolving ResourceGroup on property: oc_ExpeCommHyper

</TraceText>
</OrganizationServiceFault>
未处理的异常:System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault,Microsoft.Xrm.Sdk,Version=5.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35]:未找到方法:“System.Object System.Reflection.PropertyInfo.GetValue(System.Object)”。详细信息:
-2147220891
操作状态
0
找不到方法:“System.Object System.Reflection.PropertyInfo.GetValue(System.Object)”。
2014-09-11T12:58:09.2941554Z
[OC.CSSFieldService:OC.CSSFieldService.ServiceActivity.MyPlugin]
[424ad2a7-ea29-e411-be7f-00155d0aa109:OC.CSSFieldService.ServiceActivity.MyPlugin:创建设备]
FSE对象类型:OC.Data.Equipment
正在解析属性上的ResourceGroup:oc_ExpeCommHyper

正如您所看到的,即使跟踪行“尝试获取值”也不起作用。异常未被捕获。。。我不知道该怎么办。有什么想法吗?

好的,我想出来了。服务器安装了Microsoft.NET4.0,我安装了.NET4.5

在.NET 4.5中,PropertyInfo.GetValue方法有一个新的重载-它是PropertyInfo.GetValue(对象obj),因为在4.0中只有PropertyInfo.GetValue(对象obj,对象[]索引器)

我只需要替换:

 OptionSetValue skillLevel = (OptionSetValue)optionSetsProperty.GetValue(fse);

工作得很有魅力

 OptionSetValue skillLevel = (OptionSetValue)optionSetsProperty.GetValue(fse);
OptionSetValue skillLevel = (OptionSetValue)optionSetsProperty.GetValue(fse, null);