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.
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.
(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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With