dazinator / CrmAdo

An ADO.NET Provider for Dynamics Crm
6 stars 4 forks source link

Microsoft SDK assembly doesn't run correctly from GAC #41

Closed dazinator closed 9 years ago

dazinator commented 9 years ago

Due to a limitation with a Microsoft CRM SDK assembly which I have raised here: https://community.dynamics.com/crm/f/117/t/144464.aspx - CrmAdo doesn't work unless the Microsoft.Xrm.Client.dll is in the client applications local bin directory. This is difficult when the client application is something like Visual Studio.

So, in order to work around this, I need take control of how the Microsoft.Xrm.Client.dll is resolved and ensure that it does not get loaded from the GAC.

This means:-

  1. Change the installer so that the Microsoft.Xrm.Client.dll is not deployed into the GAC.
  2. Either use the "AppDomain.CurrentDomain.AssemblyResolve" Event to handle loading this DLL, which looks something like:
Assemly.Load(Path.Combine(@"c:\ProgramFiles\CrmAdo\",args.Name.Substring(0, args.Name.IndexOf(",")) + ".dll"))

or make the installer add a codeBase element in the machine.config to tell .NET explicitly where to load the assembly from. i.e something like

<runtime>
 <assemblyBinding>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Xrm.Client.dll" publicKeyToken="f0b5026b59d5645e"   
     culture="neutral" />
    <codeBase version="1.0.0.0" href="file:///C:/ProgramFiles/CrmAdo/Microsoft.Xrm.Client.dll" />
  </dependentAssembly>
 </assemblyBinding>
</runtime>

Or.. Make the installer copy the "Microsoft.Xrm.Client.dll" to the Visual Studio Ide directory. This is the least desirable solution. However this will mean that when the VS DDEX extension runs, it will resolve the Microsoft.Xrm.Client.dll privatley without resorting to the GAC. This will atleast allow the Visual Studio Extension to work. Other applications that reference CrmAdo can include the Microsoft.Xrm.Client.dll locally too.

dazinator commented 9 years ago

Outcome was the installer now detects if supported versions of VS are installed and copies the Microsoft.Xrm.Client assembly to the relevent VS IDE folders. This allows VS components / extensions that want to use CrmAdo to work. This solution will remain until Microsoft Fix this issue with the SDK.