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.