13

I have been trying to deploy a new asp.net mvc project to Azure for production. Everything works locally but I'm having troubles with assemblies when deploying.

Upon navigating to most pages, I started receiving an error of:

Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

Using the information from : https://stackoverflow.com/a/8824250/1411764 I caught the exception:

Could not load file or assembly 'Microsoft.Web.Administration, 
Version=7.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or 
one of its dependencies. The system cannot find the file specified.

Microsoft.Web.Administration appears to be an IIS assembly.

I then added Microsoft.Web.Administration to the project using Nuget.

Now I'm stuck with a new error:

Could not load file or assembly 'Microsoft.Web.Administration' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

I have tried adding a binding redirect into web.config

<dependentAssembly>
   <assemblyIdentity name="Microsoft.Web.Administration" publicKeyToken="31BF3856AD364E35" culture="neutral" />
   <bindingRedirect oldVersion="0.0.0.0-7.9.0.0" newVersion="7.9.0.0" />

At this point it breaks straight away and I can't load any page. (Seems worse than when I didn't have the extra dll.

I've read many similar posts but can't seem to figure it out. Hopefully I'm doing something simple wrong from a lack of understanding regarding Azure. Any help would be much appreciated.

Updated Info

Right clicking properties for reference Microsoft.Web.Administration:

Copy Local: True

Runtime Version v2.0.50727

Version: 7.0.0.0

Calling assembly : Microsoft.WebMatrix.Core, Version=8.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

Update 2 - from comments:

After settings binding to 7.0.0.0 it now compiles again on the server and can display some pages but I'm still catching the previous error.

Could not load file or assembly 'Microsoft.Web.Administration, Version=7.9.0.0, 
Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. 
The located assembly's manifest definition does not match the assembly reference. 
(Exception from HRESULT: 0x80131040)

I assume from this that Nuget has only supplied version 7.0.0.0 however something thinks it needs 7.9.0.0.

Update 3: Success

I started looking into the version number differences and found this stack question which explains some differences between IIS and IISExpress.

For now I changed the redirect from 7.9.0.0 to 7.0.0.0 which seems to of solved the issue.

<bindingRedirect oldVersion="0.0.0.0-7.9.0.0" newVersion="7.0.0.0" />

The assemblies now work and the pages are all loading.

This solution feels very hacky though. Is binding to a lower version bad practice or likely to cause issues in the future? I'm worried that I should be addressing the code calling the different IIS versions.

Community
  • 1
  • 1
Robert
  • 827
  • 9
  • 16
  • Is it a Web Role or a Web Site? – haim770 Nov 27 '14 at 08:41
  • Can you check FileInfo for that Microsoft.Web.Administration.dll and add AssemblyInfo and File version of the dll, I suspect they might not match 100%. – Alexey Shcherbak Nov 27 '14 at 08:42
  • Try to enable Fusion log to get more info about exact binding problems http://stackoverflow.com/questions/4679279/debug-net-assembly-binding-aka-find-what-dll-is-used-and-why – Alexey Shcherbak Nov 27 '14 at 08:45
  • This link is showing better way to enable fusino logging http://stackoverflow.com/questions/255669/how-to-enable-assembly-bind-failure-logging-fusion-in-net – Alexey Shcherbak Nov 27 '14 at 09:04
  • @haim770 I'm not 100% sure tbh. I had an existing .netmvc app which I added a web role project to. I separately created a website, db and storage container on the Azure portal and then used VS publish. (Sorry I'm very new with Azure). (db and storage blobs are working) – Robert Nov 27 '14 at 09:13
  • I assume you're using `Microsoft.Web.Administration` in your `WebRole.cs` file? Probably to tweak some IIS behavior. – haim770 Nov 27 '14 at 09:14
  • @haim770 Just did a quick google around. I don't actually have a Webrole.cs file on any classes anywhere that implement RoleEntry point and the code examples seem to have. Inside my Azure project I have Role Folder: -> Diagnostics.wadcfgx, and then ServiceConfiguration (cloud, local) and Service Definition – Robert Nov 27 '14 at 09:20
  • 2
    If Visual Studio claims that the version is actually `7.0.0` why is the `bindingRedirect` pointing to `7.9.0.0`? – haim770 Nov 27 '14 at 09:21
  • For an existing mvc app I'd recommend you to add WebRole file which inherits from RoleEntryPoint. Even if it's empty. Have you tried to enable Fusion logging to find binding problems ? Also you can RDP to your running instance and investigate it there. – Alexey Shcherbak Nov 27 '14 at 10:43
  • Thanks for the suggestions so far. Unfortunately I had to leave and haven't had a chance to explore all suggestions here yet. I did edit the binding quickly as suggested and added the results to the question under update 2. Next real chance I have to sit down for more than a few minutes I'll check out fusion log. – Robert Nov 27 '14 at 12:29
  • Update 3 solved my problem! Thanks for updating! – Eduardo Xavier Mar 18 '15 at 23:07
  • The NuGet package should not be used, https://blog.lextudio.com/2015/05/whats-microsoft-web-administration-and-the-horrible-facts-you-should-know/ – Lex Li May 30 '15 at 04:49
  • @Robert: Can you create an answer with what you did and mark it as answered (when you can) – garfbradaz Jul 12 '17 at 13:34
  • I have a similar issue. NOT using the NuGet package. EXE file built on Windows 10 with IIS 10 runs fine on Windows Server 2012 with IIS 8.5 and looks for version 7.0.0.0 of `Microsoft.Web.Administration`. EXE file built on our build server (unknown system) fails on Windows Server 2012 with IIS 8.5 and looks for version 7.9.0.0 of `Microsoft.Web.Administration`. Will post an answer when I have found a solution. – Florian Winter Sep 12 '17 at 12:47

1 Answers1

3

This may not be an optimal solution, but it is a summary of suggestions from the comments, the original question and research and testing I did, as well as my interpretation of the results. I hope it will be useful. Thanks to everyone who contributed to solving this.

TL;DR: Install IIS and IIS Management features on your BUILD system or build on a system where these are installed.

This error means that your application is trying to load the IIS Express version of Microsoft.Web.Administration, which is probably not what you want on a production server.

  • Version 7.0.0.0 is for IIS
  • Version 7.9.0.0 is for IIS Express

(see also https://stackoverflow.com/a/11216326/2279059)

To make your application work on a production system with the real IIS, you have to build it on a system where the IIS (not only the IIS Express) version of Microsoft.Web.Administration is installed, i.e., you have to install IIS and enable the IIS Management feature(s) (which have slightly different names on different Windows versions/editions), so C:\Windows\system32\inetsrv\Microsoft.Web.Administration.DLL exists.

In your project file, the reference to the DLL should look like this:

<Reference Include="Microsoft.Web.Administration, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <HintPath>C:\Windows\System32\inetsrv\Microsoft.Web.Administration.dll</HintPath>
  <SpecificVersion>True</SpecificVersion>
</Reference>

(This is for Visual Studio 2012 and might be different for newer versions!)

Note that if you turn off SpecificVersion or set Version to 7.9.0.0, your application will still work, as long as you build it on a system where IIS and Microsoft.Web.Administration are installed. However, if you build it on a system where the DLL is missing, then your application may be linked to the IIS Express version of the DLL (which ships with Visual Studio), causing the problem described in the question. Therefore, you better specify the version. This will make the build fail if the DLL is not installed on the build system, which is easier to debug than a "successful" build that produces a broken executable.

There is also a NuGet package called Microsoft.Web.Administration on the web. According to older information (https://blog.lextudio.com/2015/05/whats-microsoft-web-administration-and-the-horrible-facts-you-should-know/), this is not a Microsoft package and should not be used. However, it seems that Microsoft has now taken ownership of the package. While I could not find it on NuGet in Visual Studio 2012, an application I wrote in Visual Studio 2015 uses this package and works fine on multiple versions of Windows (such as Windows Server 2012 and Windows 10, which have different versions of IIS). Using the NuGet package may therefore resolve all of these issues.

Florian Winter
  • 4,750
  • 1
  • 44
  • 69