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.Edm.dll    5.2.0.0
Microsoft.Data.OData.dll 5.2.0.0
System.Spatial.dll            5.2.0.0

Microsoft.Data.Services is a version 5.0.0.0 : 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="1.0.0.0-5.0.0.0" newVersion="5.2.0.0" />     </dependentAssembly>    </assemblyBinding> </runtime>

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


Happy programming.....


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

No comments:

Post a Comment