49

I have an HTTPModule that I use to redirect traffic between a website in my data center and a website running on the Azure platform. This HTTPModule retrieves its redirect rules from Azure Table Storage.

Redirects work fine on my local dev machine as well as when running on Azure. However, when I deploy the module to my data center servers ( IIS 7, WS 2008 R2 Standard 64bit, .NET 4.0, ASP.NET 4.0 ) I receive the following error

Parser Error Message: Could not load file or assembly 'msshrtmi' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Line 124:                <add assembly="System.Web.DynamicData, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
Line 125:                <add assembly="System.Web.ApplicationServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
Line 126:                <add assembly="*" />
Line 127:            </assemblies>
Line 128:            <buildProviders>

Source File: C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\web.config    Line: 126 

"msshrtmi.dll" actually exists in my deployment bin directory.

If I remove this dll the data center site works fine but but the HTTPModule fails to load its configuration data from Table Storage and instead throws the following error

---> System.TypeInitializationException: The type initializer for 'Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'msshrtmi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
   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()

Also, I have manually included "Microsoft.WindowsAzure.ServiceRuntime.dll" as part of the deployment to ensure it is available on the data center servers.

William Edmondson
  • 3,519
  • 3
  • 29
  • 39

16 Answers16

30

It seems that Azure projects are very sensitive to that particular file. From: http://social.msdn.microsoft.com/Forums/en-US/windowsazuretroubleshooting/thread/0fac1f05-eb55-432f-80ac-6f15cde5b14b/

When you do a rebuild for the web role project, may I ask you to check if a msshrtmi.dll file in the bin folder or not? If yes, then please check if it is 64bit or 32bit using Dependency Walker. If it is 32bit, please try either of the following options to prevent outputing this dll file to bin folder.

  1. Target the web role project to x64 and recreate the azure service project. This option was confirmed by http://social.msdn.microsoft.com/Forums/en/windowsazure/thread/286cecf6-1423-4ef3-93f9-0eb8a67d8192. (edit: now a dead link as at February '12.)

  2. Open the web site project file using Notepad and remove the PlatformTarget element from all configuration property groups. This option is quoted from http://tomkrueger.wordpress.com/2010/07/27/azure-deployment-issue-after-upgrading-to-visual-studio-2010-and-net-4-0/.

  3. Write Post-build event command to delete msshrtmi.dll when a build action is successfully performed. To do this, please right click the web role project and select Properties. Select the Build Events tab, in the "Post-build event command line" textbox, input the following command:

cd $(TargetDir) del msshrtmi.dll

This all suggests that you'll want to check that you've built the correct configuration for deployment on your target environment. Make sure you've targetted x64 for deployment to your data centre servers.

Jeremy McGee
  • 23,314
  • 8
  • 57
  • 91
19

This solved the problem for me. Run this command within the Developer Command Prompt for VS2013.

gacutil /i "C:\Program Files\Microsoft SDKs\Windows Azure\.NET SDK\v2.0\bin\runtimes\base\x64\msshrtmi.dll"
gacutil /i "C:\Program Files\Microsoft SDKs\Windows Azure\.NET SDK\v2.0\bin\runtimes\base\x86\msshrtmi.dll"

This will register the runtime files in the Global Assembly Cache so all .NET applications will have access to it.

LongZheng
  • 1,794
  • 16
  • 15
Gael Fraiteur
  • 6,539
  • 2
  • 22
  • 30
  • 1
    This was it for me (changed v2.0 to v2.2). I guess when I installed Azure SDK 2.2 it didn't register that file to the GAC. – LongZheng Nov 18 '14 at 06:40
  • This was immensly useful. Saved hours after wrecking my head for several hours and finally resorting to StackOverflow search – ManishKG Jun 09 '15 at 01:01
  • This solution worked for me for VS2012/13 and Azure SDK 2.2 as well. I spent way too much time trying to figure this out. – Shawn H. Jun 19 '15 at 15:23
  • This also works for SxS installation of Azure SDK 2.3 and 2.7 (with different projects targeting each version). – GaryJL Sep 04 '15 at 14:00
18

I've just come across this post because I had the same issue - and unfortunately none of the above steps worked for me.

After a bit of head-scratching and messing around - I found the solution, which was remarkably/embarrassingly simple.

I blogged about it here.

  • Right-click your Azure project (the one with the blue globe).
  • Click the "Application" tab.
  • Note that there is a button telling you that you have a newer SDK installed? CLICK IT!

So, it turns out that some minor changes get made to a few files that make all the difference:

  • .csdef file - 'schemaVersion' is updated.
  • .ccproj - 'ProductVersion' and 'CloudExtensionsDir' are updated.
  • .csproj - You're Azure SDK references will be updated (ServiceRuntime, Diagnostics etc.)

I think the killer was the 'CloudExtensionsDir' for me, this changed FROM:

<CloudExtensionsDir Condition=" '$(CloudExtensionsDir)' == '' ">
  $(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Windows Azure Tools\1.7\
</CloudExtensionsDir>

TO:

<CloudExtensionsDir Condition=" '$(CloudExtensionsDir)' == '' ">
  $(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Windows Azure Tools\1.8\
</CloudExtensionsDir>

Deployed to Azure, worked straight away.

Hope this helps!

PS: I should add, that I didn't need to uninstall any of the old SDK's or anything or mess around with 'Platform Targets'. Just changing this worked fine.

Rob Cooper
  • 27,684
  • 25
  • 100
  • 142
3

I ran across this after dealing with this issue for a long time. It helped me.

http://mictorino.wordpress.com/2011/09/20/vs2010-build-configurations-and-msshrtmi-dll-x86

BZink
  • 7,106
  • 10
  • 34
  • 54
2

This problem has bugged me for the last two days, and all solutions mentioned here and on other websites did not work.

Now I finally got it working. The problem was some bad combination of SDKs and tools versions installed on my machine. Some days ago I downloaded the following:

  • Windows Azure Tools 1.7
  • Windows Azure SDK Preview for Visual Studio 2012 (June 2012)

I knew the Azure SDK was a preview, but some release notes made me believe it included the current version of the (stable) SDK for Visual Studio 2010.

After I uninstalled the preview and installed Windows Azure SDK for .NET (VS 2010 SP1) - June 2012, everything worked perfectly.

cheesus
  • 11,077
  • 10
  • 64
  • 122
2

I fixed the issue we were having by simply adding a reference to

C:\Program Files\Microsoft SDKs\Windows Azure.NET SDK\2012-06\bin\runtimes\base\x86\msshrtmi.dll

It probably wont work for all scenarios but is worth a try.

Lee Englestone
  • 4,115
  • 12
  • 43
  • 79
  • 1
    He he. had the same problem recently.. Google searched and found this.. and forgot i posted previously.. well done me! solved my issue.. – Lee Englestone Oct 04 '12 at 12:15
  • This finally solved the issue for me as well after a serious waste of time uninstalling/reinstalling everyting to do with Azure. Thanks – Roger Nov 10 '12 at 16:58
2

Just add the "_bin_deployableAssemblies" folder in your projet. Put the file "C:\Program Files\Microsoft SDKs\Windows Azure.NET SDK\2012-06\bin\runtimes\base\x64\msshrtmi.dll" in this folder. Change the Build Action to "None" and just deploy...

It's work for me...

Tuizi
  • 1,493
  • 3
  • 20
  • 34
2

I may be crazy, but this happened to me because the Windows Azure SDK WAS NOT EVEN INSTALLED. Stupid, I know, but useful to keep an eye for in certain situations.

Ohad Schneider
  • 33,142
  • 10
  • 150
  • 190
2

I experienced this recently and determined that, in my case at least, this error was caused by having a reference to Microsoft.WindowsAzure.ServiceRuntime that was older than the current SDK version.

In my instance I had just upgraded to SDK 2.2 but my ServiceRuntime references were still 2.1, updating these references to 2.2 solved the problem without me having to reference msshrtmi.dll.

hermiod
  • 1,110
  • 4
  • 16
  • 24
1

I changed the "Copy Local" property to "False". And it worked for me.

Steps:

  1. Go to the reference.
  2. Open the properties of the dll from reference.
  3. Change "Copy Local" property to False.
Dark Matter
  • 1,489
  • 1
  • 22
  • 31
0

My solution to this problem was to ship msshrtmi.dll (both x86 and x64) with my app, then dynamically load them when needed.

See http://jake.ginnivan.net/azure-and-msshrtmi

Jake Ginnivan
  • 2,067
  • 16
  • 20
  • 9
    Please copy and paste the answer from your blog to here. If your blog link ever moves or dies, this answer becomes useless. – George Stocker Jun 30 '12 at 02:17
0

I've solved issue by adding msshrtmi to GAC.

Matej
  • 7,268
  • 2
  • 32
  • 43
0

I was able to get around this problem by making sure that I was referencing the X64 version of msshrtmi.dll in the GAC [1] (to match the platform target of x64 set on the project).

[1] c:\Windows\assembly\GAC_64\msshrtmi\1.7.0.0__31bf3856ad364e35>

Littm
  • 4,895
  • 4
  • 28
  • 36
0

I was having the same problem.

From your solution folder/subfolders delete all files "msshrtmi.dll" then rebuild.

vidalsasoon
  • 4,252
  • 1
  • 30
  • 40
0

I suffered from a simlar error when working with a solution that was deployable to both Windows Azure and physical hardware. The error would show up when attempting to run the solution on physical hardware. The problem stemmed from the fact that Azure libraries were part of the solution, even though they were'nt required for the on-premise build.

The simple solution is to install the Windows Azure SDK on the physical hardware. This will install the missing libraries into the GAC

Iain Hunter
  • 2,795
  • 1
  • 20
  • 10
0

This solution work for me:

  • Open the project with a notepad
  • Delete all "PlatformTarget" tags under all "PropertyGroup"
camaya
  • 357
  • 4
  • 15