Posted on:
Categories: SharePoint
Description:

Scenario

You have an Desktop Application that was built for SharePoint 2010 and you need to run in on SharePoint 2013. When the Application is ran the following error is displayed, System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified.

Background

  1. Assembly Version
    1. SharePoint 2013 doesn’t come with version 14 (2010) or 12 (2007) assemblies.
    2. For backwards compatibility, SharePoint deploys Assembly Binding Redirects for previous assembly versions, what this does is redirect any calls to version 12 or 14 to the version 15 of the assembly.
    3. Here is an example of the Assembly Binding Redirect Configuration:
      1. <dependentAssembly>
        <assemblyIdentity name="Microsoft.SharePoint" publicKeyToken="71e9bce111e9429c" culture="neutral" />
        <!-- Redirecting to version 15.0.0.0 of the assembly. -->
        <bindingRedirect oldVersion="14.0.0.0" newVersion="15.0.0.0" />
        </dependentAssembly>
  2. Common Language Runtime Version
    1. At this point you're thinking, since we have Assembly Binding Redirects, then our Application should work!
    2. The issue is that SharePoint 2010 Applications are written in .Net 3.5, while SharePoint 2013 is written in .Net 4.5
    3. .Net 4.0 introduced a new version of the CLR (Common Language Runtime), it is essentially what runs .Net code
    4. Due to the CLR update, it is not possible to load .Net 4.5 assemblies from .NET 3.5, however the other way works fine.

Solution

  1. .Net Supports a notion of a Configuration file for executables. This configuration allows you to change the way the application is ran, among many other things.
    1. More info: http://msdn.microsoft.com/en-us/library/1fk1t1t0(v=vs.110).aspx
  2. To fix our issue, we are going to tell .NET to use the 4.0 CLR, which is what .Net 4.5 uses.
  3. Assuming our application is called MyApp.exe, create a text file called MyApp.exe.config and place the following XML into it:
    1. <?xml version="1.0" encoding="utf-8"?>
      <configuration>
      <startup>
      <supportedRuntime version="v4.0"/>
      </startup>
      </configuration>
  4. Now when you run your application, it will use the 4.0 CLR and the application should work correctly with SharePoint 2013.