Search code examples
dynamics-crmdynamics-crm-2016

CrmSvcUtil: The located assembly's manifest definition does not match the assembly reference


I'm following the tutorial on how to build a console application that connects to Dynamics CRM, but stuck on the very beginning with using the CrmSvcUtil. here's what I did:

  1. copied this command:

    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
    
  2. replaced the above /url with the one listed on my CRM online deployment under Settings > Customizations > Developer Resources > Organization Service.

  3. replaced the above /username with my onmicrosoft.com username, and put quotes before and after it.

  4. replaced the above /password the way I did with /username.

  5. followed this note and put the Xrm.Client.CodeGeneration.dll on the same directory with CrmSvcUtil.exe.:

Note that the Microsoft.Xrm.Client.CodeGeneration.dll file must be in the same directory as the CrmSvcUtil.exe file

and then I ran it, and got the following error:

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)

What's the way to solve it?

EDIT: I tried using Early Bound Generator - just downloading it, connecting, and clicking "Create Entities", but it ends with an error:

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! 

Solution

  • You tagged your question as 'CRM 2016' and article that you linked is for CRM 2015. 'Xrm.Client.CodeGeneration.dll' is not present in SDK for CRM 2016. Copying this DLL from CRM 2015 SDK to bin directory of CRM 2016 SDK won't work and will result with error that you described, because this DLL depends on 7.0.0 versions not 8.0.0. You could try using CRM 2015 SDK (7.1.0) to generate CS file - it should work.