我正在关注how to build a console application that connects to Dynamics CRM上的教程,但是在使用CrmSvcUtil时就停留在最开始。 这就是我的所作所为:
复制了此命令:
CrmSvcUtil.exe /codeCustomization:"Microsoft.Xrm.Client.CodeGeneration.CodeCustomization, Microsoft.Xrm.Client.CodeGeneration" /out:Xrm.cs /url:https://<mydomain>.api.crm.dynamics.com/XRMServices/2011/Organization.svc /username:<myusername>@<mydomain>.onmicrosoft.com /password:<mypassword> /namespace:Xrm /serviceContextName:XrmServiceContext
将上面的/url
替换为我的CRM在线部署中列出的设置&gt;自定义&gt;开发者资源&gt;组织服务。
用我的onmicrosoft.com用户名替换了上面的/username
,并在它之前和之后加上引号。
用/password
替换上述/username
方式。
Xrm.Client.CodeGeneration.dll
放在与CrmSvcUtil.exe相同的目录中。:请注意,Microsoft.Xrm.Client.CodeGeneration.dll文件必须在 与CrmSvcUtil.exe文件相同的目录
然后我运行它,并得到以下错误:
CrmSvcUtil : CRM Service Utility [Version 8.1.0.7711]
c 2015 Microsoft Corporation. All rights reserved
Exiting program with exception: Could not load file or assembly 'CrmSvcUtil, Version=7.0.0.0, Cult
ure=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest
definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
CrmSvcUtil Error: 2 : Exiting program with exit code 2 due to exception : System.IO.FileLoadExcept
ion: Could not load file or assembly 'CrmSvcUtil, Version=7.0.0.0, Culture=neutral, PublicKeyToken
=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not
match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'CrmSvcUtil, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase
, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadType
FromPartialName, ObjectHandleOnStack type)
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase
, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromP
artialName)
at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolea
n reflectionOnly, StackCrawlMark& stackMark)
at System.Type.GetType(String typeName, Boolean throwOnError)
at Microsoft.Crm.Services.Utility.ServiceFactory.CreateInstance[TIService](TIService defaultSer
viceInstance, String parameterValue, CrmSvcUtilParameters parameters)
at Microsoft.Crm.Services.Utility.ServiceProvider.InitializeServices(CrmSvcUtilParameters param
eters)
at Microsoft.Crm.Services.Utility.CrmSvcUtil.get_ServiceProvider()
at Microsoft.Crm.Services.Utility.CrmSvcUtil.Run()
at Microsoft.Crm.Services.Utility.CrmSvcUtil.Main(String[] args)
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!En
ableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
CrmSvcUtil Error: 2 : ===== DETAIL ======
CrmSvcUtil Error: 2 : Source : mscorlib
Method : GetTypeByName
Date : 15:52:37
Time : 28/10/2016
Error : Could not load file or assembly 'CrmSvcUtil, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
or one of its dependencies. The located assembly's manifest definition does
not match the assembly reference. (Exception from HRESULT: 0x80131040)
Stack Trace : at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean
ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder,
Boolean loadTypeFromPartialName, ObjectHandleOnStack type)
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase,
Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName)
at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)
at System.Type.GetType(String typeName, Boolean throwOnError)
at Microsoft.Crm.Services.Utility.ServiceFactory.CreateInstance[TIService](TIService defaultServiceInstance, String parameterValue, CrmSvcUtilParameters parameters)
at Microsoft.Crm.Services.Utility.ServiceProvider.InitializeServices(CrmSvcUtilParameters parameters)
at Microsoft.Crm.Services.Utility.CrmSvcUtil.get_ServiceProvider()
at Microsoft.Crm.Services.Utility.CrmSvcUtil.Run()
at Microsoft.Crm.Services.Utility.CrmSvcUtil.Main(String[] args)
解决问题的方法是什么?
编辑:我尝试使用Early Bound Generator - 只需下载,连接并点击&#34;创建实体&#34;,但它以错误结束:System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at DLaB.CrmSvcUtilExtensions.Entity.CodeWriterFilterService.GenerateOptionSet(OptionSetMetadataBase optionSetMetadata, IServiceProvider services)
at Microsoft.Crm.Services.Utility.CodeGenerationService.BuildAttributeOptionSet(EntityMetadata entity, AttributeMetadata attribute, CodeTypeMember attributeMember, ServiceProvider serviceProvider)
at Microsoft.Crm.Services.Utility.CodeGenerationService.BuildEntity(EntityMetadata entity, ServiceProvider serviceProvider)
at Microsoft.Crm.Services.Utility.CodeGenerationService.BuildEntities(EntityMetadata[] entityMetadata, ServiceProvider serviceProvider)
at Microsoft.Crm.Services.Utility.CodeGenerationService.BuildCodeDom(IOrganizationMetadata organizationMetadata, String outputNamespace, ServiceProvider serviceProvider)
at Microsoft.Crm.Services.Utility.CodeGenerationService.Microsoft.Crm.Services.Utility.ICodeGenerationService.Write(IOrganizationMetadata organizationMetadata, String language, String outputFile, String outputNamespace, IServiceProvider services)
at DLaB.CrmSvcUtilExtensions.BaseCustomCodeGenerationService.WriteInternal(IOrganizationMetadata organizationMetadata, String language, String outputFile, String targetNamespace, IServiceProvider services)
at DLaB.CrmSvcUtilExtensions.BaseCustomCodeGenerationService.Write(IOrganizationMetadata organizationMetadata, String language, String outputFile, String targetNamespace, IServiceProvider services)
Output file was not updated or not found!
答案 0 :(得分:2)
您将自己的问题标记为&#39; CRM 2016&#39;您链接的文章适用于CRM 2015.&#39; Xrm.Client.CodeGeneration.dll&#39;在SDK for CRM 2016中不存在。将此DLL从CRM 2015 SDK复制到CRM 2016 SDK的bin目录不会起作用,并且会导致您所描述的错误,因为此DLL依赖于7.0.0版本而不是8.0。 0。您可以尝试使用CRM 2015 SDK(7.1.0)生成CS文件 - 它应该可以工作。