Monday, June 16, 2014

Step by step how to fix the error "'The type initializer for 'System.Data.Services.Providers.ResourceType' threw an exception.'

       By Carmel Shvartzman

In this tutorial we'll learn how to fix the error "'The type initializer for 'System.Data.Services.Providers.ResourceType' threw an exception.' while deploying an ODATA WCF Data Service  in a web host
The error is caused because there is a specific version of an assembly missing. 
Open the references of your MVC Visual Studio app, those related to ODATA, and you'll see something like this : 

Microsoft.Data.Services is a version : but the version of the assemblies should be the same. If not so, there could be  functions missing and other problems of lack of fitness between them.
Open the Package Manager Console and enter the following expression, to put in sync the ASSEMBLY VERSIONS :

> Install-Package Microsoft.Data.Services -Version 5.2.0

This will bring the required DLL and remove the older version of the assembly.

You can also set in the web.config what will be  the new version of the assembly, but it is not required to do so:

<runtime>   <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">     <dependentAssembly>       <assemblyIdentity name="Microsoft.Data.Services"                     publicKeyToken="XXXX" />             <bindingRedirect oldVersion="" newVersion="" />     </dependentAssembly>    </assemblyBinding> </runtime>

Just change the version to the one you need :!!

Happy programming.....

כתב: כרמל שוורצמן