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

半城伤御伤魂 提交于 2019-11-29 04:35:06

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>

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.

Sean Mahan

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?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!