Fixing the msshrtmi.dll issue on Windows Server 2012 in Azure

This blog has moved to http://mode13h.azurewebsites.net.

Fixing the msshrtmi.dll issue on Windows Server 2012 in Azure

Rate This
  • Comments 3

As part of a startup task, I sometimes have to install programs that are not part of the Azure role. For instance, I have a monitoring system that logs ETW and perf counter events. My intention is to keep this as a separate Windows service so that it's not in the same process as my worker role. This has worked just fine up until moving to Windows Server 2012. Now I get this error:

Unhandled Exception: System.TypeInitializationException: The type initializer for 'Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment' threw an exception. ---> System.IO.FileLoadException: Could not load file or assembly 'msshrtmi.dll' or one of its dependencies. A dynamic link library (DLL) initialization routine failed. (Exception from HRESULT: 0x8007045A)
   at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.InitializeEnvironment()
   at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment..cctor()
   --- End of inner exception stack trace ---
   at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.get_IsAvailable()

If you get into a situation similar to mine, the fix is simple. Add the following to the exe.config file:

<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <runtime>
    <NetFx40_LegacySecurityPolicy enabled="false" />
  </runtime>
</configuration>

Leave a Comment
  • Please add 5 and 4 and type the answer here:
  • Post
  • useLegacyV2RuntimeActivationPolicy="true"

    Genius! I also have a small exe running as a startup task and hit this problem when updating to 2012 in Azure. Thanks Dustin.

  • Thanks! That did the trick!

  • Works like a charm! Thanks!

Page 1 of 1 (3 items)