The type initializer for 'Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment' threw an exception

后端 未结 3 1170
忘了有多久
忘了有多久 2020-12-17 01:55

I am trying to use Windows Azure Caching to store sessions in a MVC4 application. I build a application following steps from Link but when i try to make object of DataCache

相关标签:
3条回答
  • 2020-12-17 02:10

    I had the same issue. The solution was to point all referenced Azure assemblies in every project to the same source (for me the dlls in the SDK folder). The NuGetManager copies the dlls into the main project path under packages and points the references to these dlls.

    0 讨论(0)
  • 2020-12-17 02:12

    I experienced this when migrating from Azure SDK 2.3 to SDK 2.4.

    I noticed the migration automatically fixed all references to the service runtime for my web and worker roles, i.e.

    C:\Program Files\Microsoft SDKs\Windows Azure\.NET SDK\v2.3\ref\Microsoft.WindowsAzure.ServiceRuntime.dll
    

    changed to:

    C:\Program Files\Microsoft SDKs\Azure\.NET SDK\v2.4\ref\Microsoft.WindowsAzure.ServiceRuntime.dll
    

    However any assemblies referenced from the web/worker roles that referenced this assembly didn't update so I had to do it manually.

    In addition I had to update the web.config and app.config entries to reference 2.4.0.0

    <dependentAssembly>
        <assemblyIdentity name="Microsoft.WindowsAzure.ServiceRuntime" publicKeyToken="31bf3856ad364e35" culture="neutral" />
         <bindingRedirect oldVersion="0.0.0.0-2.4.0.0" newVersion="2.4.0.0" />
    </dependentAssembly>
    
    0 讨论(0)
  • 2020-12-17 02:15

    I've solved a similar issue by adding this to App.config:

    <startup useLegacyV2RuntimeActivationPolicy="true">
      <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
    </startup>
    

    This is because, I believe, ServiceRuntime.dll (or one of its dependencies) is a "mixed-mode" assembly. A little more info about what that means, and the config lines above, can be found here: What does 'useLegacyV2RuntimeActivationPolicy' do in the .NET 4 config?

    0 讨论(0)
提交回复
热议问题