开发人员工具包中的组织服务为null,用于开发Dynamics CRM插件

时间:2015-08-04 08:37:32

标签: c# plugins dynamics-crm-2011

我编写了一个插件,该插件在异常中抛出OrganizationService对象,以检查它是否包含任何组织内容。但我遇到了例外。我附上以下内容并期待您的指导。 TIA !!

代码:

protected void ExecutePostRequestforApprovalCreate(LocalPluginContext localContext)
        {
            if (localContext == null)
            {
                throw new ArgumentNullException("localContext");
            }

            IPluginExecutionContext context = localContext.PluginExecutionContext;
            IOrganizationService service = localContext.OrganizationService;

            var serviceContext = new OrganizationServiceContext(service);

            throw new ArgumentException("Exception sent:"+service.ToString());
}

例外:

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: System.ArgumentNullException: Value cannot be null.
Parameter name: The plug-in type could not be found in the plug-in assembly: approveCheckListTest.Plugins.PostRequestforApprovalCreateDetail: 
<OrganizationServiceFault xmlns:i="www.w3.org/.../XMLSchema-instance" xmlns="schemas.microsoft.com/.../Contracts">
  <ErrorCode>-2147220970</ErrorCode>
  <ErrorDetails xmlns:d2p1="schemas.datacontract.org/.../System.Collections.Generic">
    <KeyValuePairOfstringanyType>
      <d2p1:key>CallStack</d2p1:key>
      <d2p1:value xmlns:d4p1="www.w3.org/.../XMLSchema" i:type="d4p1:string">   at Microsoft.Crm.Application.Platform.ServiceCommands.PlatformCommand.XrmExecuteInternal()
   at Microsoft.Crm.Application.Platform.ServiceCommands.CreateCommand.Execute()
   at Microsoft.Crm.Application.Platform.EntityProxy.Create(Boolean performDuplicateCheck, Guid auditingTransactionId)
   at Microsoft.Crm.Application.Platform.EntityProxy.Create(Boolean performDuplicateCheck)
   at Microsoft.Crm.Application.Forms.AppForm.SaveEntity(EntityProxy entity, FormEventId eventType, String redirectPath, Boolean performDuplicateCheck)</d2p1:value>
    </KeyValuePairOfstringanyType>
  </ErrorDetails>
  <Message>System.ArgumentNullException: Value cannot be null.
Parameter name: The plug-in type could not be found in the plug-in assembly: approveCheckListTest.Plugins.PostRequestforApprovalCreate</Message>
  <Timestamp>2015-08-04T08:32:19.3215616Z</Timestamp>
  <InnerFault i:nil="true" />
  <TraceText>
[approveCheckListTest.Plugins: approveCheckListTest.Plugins.PostRequestforApprovalCreate]
[613491a3-813a-e511-800b-005056b743f7: PostRequestforApprovalCreate]
</TraceText>
</OrganizationServiceFault>

1 个答案:

答案 0 :(得分:0)

错误通常是由服务器和Visual Studio项目之间的Microsoft.Xrm.Sdk SDK版本不一致引起的。

删除引用,重建项目并添加正确的SDK版本作为参考。再次重建并使用插件注册工具导入。