Handling exception when using RoleEnvironment.GetConfigurationSettingValue in Windows Azure Startup Task

It is possible that Using RoleEnvironment.GetConfigurationSettingValue in your startup task may cause the following exception in your Windows Azure web application:


The type initializer for 'Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment' threw an exception InnerException: System.IO.FileLoadException
Message=Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.

To solve this problem you can add useLegacyV2RuntimeActivationPolicy attribute to the console app’s exe.config file, it resolved the error.



  <startup useLegacyV2RuntimeActivationPolicy="true">

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



Comments (0)

Skip to main content