Pogo69's Blog

March 31, 2011

Microsoft.Crm.Sdk.dll v4.0 vs v5.0 – CRM 4.0 SDK Library Redirection to CRM 2011

Filed under: .NET, C#, CRM, Cutting Code — Tags: , , , , — pogo69 [Pat Janes] @ 11:12

NB: This issue has been fixed in CRM 2011 Rollup 1.

We completed the migration of our internal CRM 4.0 system to CRM 2011 last week.  It all went reasonably smoothly with only what appear to be a few lingering javascript customisations that don’t play nicely with the new system.

We also run an externally available Customer Support Portal using the Customer Portal Accelerator from CodePlex.  This web application leverages the XRM libraries in the CRM 4.0 SDK to provide a reference implementation for Customer Support, upon which developers with the requisite skills can build additional functionality.

While it would be nice to move to the new CRM 2011 specific versions of the Portal Accelerators, I had to get the existing version up and running ASAP, so that our customers didn’t experience undue difficulties with the transition; let’s face it, as CRM Developers, who ever has time to work on their internal systems when there’s client work to do?  In order to get it all working on the new system, I had to change a few things.  In case anyone else needs to do the same, the following describes the process.

Web.config

CRM 2011 utilises the .NET framework v4.0.  Many of the Configuration Sections in a Web.config generated for a .NET 3.5 web application are no longer necessary in .NET 4.0 as they are specified in the Machine.config and are therefore inherited by each Web Application.

I made the following modifications to my Web.Release.config (Config Transform for Release Builds) to remove the offending sections when I compiled a Release build:

<configuration xmlns:xdt="<a href="http://schemas.microsoft.com/XML-Document-Transform">http://schemas.microsoft.com/XML-Document-Transform</a>">
  <configSections>
    <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
        <section name="scriptResourceHandler" xdt:Locator="Match(name)" xdt:Transform="Remove"/>
        <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
          <section name="jsonSerialization" xdt:Locator="Match(name)" xdt:Transform="Remove"/>
          <section name="profileService" xdt:Locator="Match(name)" xdt:Transform="Remove"/>
          <section name="authenticationService" xdt:Locator="Match(name)" xdt:Transform="Remove"/>
          <section name="roleService" xdt:Locator="Match(name)" xdt:Transform="Remove"/>
        </sectionGroup>
      </sectionGroup>
    </sectionGroup>
  </configSections>
...
</configuration>

CRM SDK Library – Redirect from v4.0 to v5.0

This was a tricky one.  It seems that the installation of CRM 2011 places a machine-wide redirection for the Microsoft.Crm.Sdk.dll from the v4.0 to the v5.0 version.

This means that any application running on the CRM Server that relies on the Microsoft.Crm.Sdk.dll assembly will load the v5.0 version even if the v4.0 version exists in the application’s /bin folder!  I verified this by enabling Fusion logging:

In order to be able to successfully load the v4.0 version of the assembly and execute your legacy v4.0 code, you have to override the <publisherpolicy /> set at the machine level, with the following addition to the application configuration file:

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  ...
  <runtime>
    ...
    <assemblyBinding appliesTo="v4.0.30319" xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Crm.Sdk" publicKeyToken="31bf3856ad364e35"/>
        <publisherPolicy apply="no"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  ...
</configuration>

5 Comments »

  1. The solution is in the right direction except I had to make one tweak in order to make it work for us. I had to set “BindingRedirect” option instead of PublisherPolicy.

    <!—->

    Comment by Pranav M. Shah — July 30, 2011 @ 04:34

    • can you pease tell me the exact path of config , where i have to paste that publisher settings

      Thanks

      Comment by Venky — January 31, 2012 @ 22:21

      • Path is the same as the executable for which the config file provides settings.

        Comment by pogo69 — March 12, 2012 @ 12:06

  2. Is there anyway to do this with a ASP.NET web service web config file?

    Comment by Nestor — June 7, 2012 @ 01:21

    • It will work for the web.config in exactly the same way as for an app.config.

      Note however; this should be unnecessary if your CRM 2011 Deployment has Rollup 1 or greater applied.

      Comment by pogo69 — June 7, 2012 @ 09:14


RSS feed for comments on this post. TrackBack URI

Leave a reply to pogo69 Cancel reply

Blog at WordPress.com.