Autofac 3.4 is missing, while 3.5 is called - asp.net-mvc

Attempting to run the MVC 5.2 project, which is built successfuly, got the following error:
An exception of type 'System.IO.FileLoadException' occurred in
ProjectNamespace.WebUI.dll but was not handled in user code
Additional information: Could not load file or assembly 'Autofac,
Version=3.4.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da' or
one of its dependencies. The located assembly's manifest definition
does not match the assembly reference. (Exception from HRESULT:
0x80131040)
Assembly manager loaded from:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll Running under
executable C:\Program Files (x86)\IIS Express\iisexpress.exe
--- A detailed error log follows.
=== Pre-bind state information === LOG: DisplayName = Autofac, Version=3.4.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da
(Fully-specified) LOG: Appbase = file:///C:/ProjectPath/WebUI/ LOG:
Initial PrivatePath = C:\ProjectPath\WebUI\bin Calling assembly :
Autofac.Integration.Mvc, Version=3.3.0.0, Culture=neutral,
PublicKeyToken=17863af14b0044da.
=== LOG: This bind starts in default load context. LOG: No application configuration file found. LOG: Using host configuration file:
C:\Users\me\Documents\IISExpress\config\aspnet.config LOG: Using
machine configuration file from
C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Autofac, Version=3.4.0.0, Culture=neutral,
PublicKeyToken=17863af14b0044da LOG: Attempting download of new URL
file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary
ASP.NET Files/root/5c8bedab/6a36492/Autofac.DLL. LOG: Attempting
download of new URL
file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary
ASP.NET Files/root/5c8bedab/6a36492/Autofac/Autofac.DLL. LOG:
Attempting download of new URL
file:///C:/ProjectPath/WebUI/bin/Autofac.DLL. WRN: Comparing the
assembly name resulted in the mismatch: Minor Version ERR: Failed to
complete setup of assembly (hr = 0x80131040). Probing terminated.
My web.config has the following settings:
<dependentAssembly>
<assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.5.0.0" newVersion="3.5.0.0" />
</dependentAssembly>
Spent hours trying to resolve it, but failed. Please help.

This problem has become quite common. It seems to come up when you have the Autofac, Autofac.Mvc5 and Microsoft.AspNet.Mvc>5.1.0 packages, even though Autofac.Mvc5 is stated to work with Microsoft.AspNet.Mvc(≥ 5.1.0 && < 6.0.0).
I suggest the classic solution of checking and adding the appropriate assembly binding redirects for autofac, not only in the project which references it but in projects referencing that project as well.
Another potential problem is having two entries for the
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
in your config, if you have your bindings in the second one move them to the first one. That fixed it for me in a situation where I was also encrypting some configuration settings and for some reason the binding redirects were not copied into the resulting config file.
I highly recommend the Assembly Binding Log Viewer, it helped me a lot in figuring out the issue, even though my final solution was a cowardly one, going to Autofac3.4.0.0 and Microsoft.AspNet.Mvc 5.1.0. I spent way too much time on fixing the problem.
Also, for those who are interested you can use the nuget manager to detect and fill in your assembly binding redirects: Get-Project -All | Add-BindingRedirect (from here). It might need some additions afterwards depending on your porjects and references but at least it's going to give you a clean slate to begin with.
Update
Microsoft.AspNet.Mvc 5.2.3 was released so I decided to try again. I updated every package involved in the "conflict" to the latest version (Autofac 3.5.2, Autofac.Mvc5 3.3.4, Microsoft.AspNet.Mvc 5.2.3). I updated the redirect bindings and it worked.

Related

Cannot resolve dependency to assembly FSharp.Core 4.4.1.0 when using VS 2017

I have been developing in VS 2015 and F# 4.0 (4.4.0.0) for quite some time.
With the release of VS 2017, I want to open solutions in the newest VS for development work, but still for a while keep the projects as VS 2015, F# 4.0, .NET 4.5.2. The build server will also have to use VS 2015 for a while.
As far as I can remember, this kind of scenario has not been problematic in earlier VS version upgrades, but then I don't think I used F# at that time.
I opened the solution and tried to compile. I get this error in a C# application project. (There are other C# applications, and at least one references an F# library.)
Unknown build error, 'Cannot resolve dependency to assembly 'FSharp.Core, Version=4.4.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' because it has not been preloaded. When using the ReflectionOnly APIs, dependent assemblies must be pre-loaded or loaded on demand through the ReflectionOnlyAssemblyResolve event.
All my F# projects in the solution are 4.0 (4.4.0.0). I double checked.
Why is this happening?
I searched for "4.4.1.0", and discovered that the "obj" folder of the C# project had a .exe.config file that differed from the app.config. It had this extra information that is not in the app.config of the project.
<runtime>
...
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.4.1.0" newVersion="4.4.1.0" />
</dependentAssembly>
</assemblyBinding>
Why is this appended automatically, and why only in this particular C# project?
I tried to copy that section to the app.config of the project, and change it to 4.4.0.0 in both places, but that didn't work. Also tried to use "4.4.1.0" as upper limit of old version, and have "4.4.0.0" as new version, but still didn't work. Same compiler error.
Then I removed that section, and I referenced FSharp.Core 4.4.0.0 in the C# project. That finally got rid of the compile error.
The I ran the program. It crashed with this exception.
Unhandled exception: Could not load file or assembly 'FSharp.Core, Version=4.4.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
I reinserted the section with the redirect, and now the program runs fine.
Just to sum up, I added a reference to FSharp.Core 4.0, and the redirect looks like this
<bindingRedirect oldVersion="0.0.0.0-4.4.1.0" newVersion="4.4.0.0" />
With these modifications, the solution still works as expected also in VS 2015.
I had the same problem, maybe this is helpful for someone:
In my case, the cause was that some of my C# projects with transitive dependencies on FSharp.Core were referencing the runtime's assembly installed on my system directly, instead of using the NuGet package. I.e. the reference didn't have a hint path pointing to the NuGet packages folder, and thus was picking the assembly from C:\Program Files\FSharp\... from the F# SDK. I solved this by removing the reference and reinstalling the FSharp.Core NuGet package.
So this:
<Reference Include="FSharp.Core, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
Turns into:
<Reference Include="FSharp.Core, Version=4.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\FSharp.Core.4.5.2\lib\net45\FSharp.Core.dll</HintPath>
<Private>True</Private>
</Reference>
Check the assembly references of the assembly in the message. For me I had a reference to assembly X which had a reference to Y. Because Y was missing, I got this error. By referencing Y, the error was resolved for me.

Error creating a DevExpress controls for ASP.NET MVC empty project manually

I am using Visual Web Developer 2010 Express. I need to use DevExpress controls for an ASP.NET MVC 4 project.
So, I downloaded DevExpress Universal Edition something that has ASP.NET MVC controls.
Since I do not see a DevExpress ASP.NET MVC Empty project template, I am manually creating one following the instructions provided here:
http://documentation.devexpress.com/#AspNet/CustomDocument8163
However, when I start my application, I get this yellow screen of death that says:
Configuration Error
Description: An error occurred during the processing of a configuration file required
to service this request. Please review the specific error details below and modify
your configuration file appropriately.
Parser Error Message: Could not load file or assembly 'DevExpress.Data.v12.2,
Version=12.2.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a' or one of its
dependencies. The system cannot find the file specified.
Source Error:
Line 39: <compilation debug="true" targetFramework="4.0">
Line 40: <assemblies>
Line 41: <add assembly="DevExpress.Data.v12.2, Version=12.2.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
Line 42: <add assembly="DevExpress.Web.v12.2, Version=12.2.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
Line 43: <add assembly="DevExpress.Web.ASPxHtmlEditor.v12.2, Version=12.2.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
Source File: C:\Users\computer\Documents\Visual Studio 2010\Projects\MvcApplication5\MvcApplication5\web.config Line: 41
Assembly Load Trace: The following information can be helpful to determine why the assembly 'DevExpress.Data.v12.2, Version=12.2.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a' could not be loaded.
=== Pre-bind state information ===
LOG: User = computer-VAIO\computer
LOG: DisplayName = DevExpress.Data.v12.2, Version=12.2.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a
(Fully-specified)
LOG: Appbase = file:///C:/Users/computer/Documents/Visual Studio 2010/Projects/MvcApplication5/MvcApplication5/
LOG: Initial PrivatePath = C:\Users\computer\Documents\Visual Studio 2010\Projects\MvcApplication5\MvcApplication5\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\computer\Documents\Visual Studio 2010\Projects\MvcApplication5\MvcApplication5\web.config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: DevExpress.Data.v12.2, Version=12.2.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a
LOG: Attempting download of new URL file:///C:/Users/computer/AppData/Local/Temp/Temporary ASP.NET Files/root/8847955d/8ce8b26b/DevExpress.Data.v12.2.DLL.
LOG: Attempting download of new URL file:///C:/Users/computer/AppData/Local/Temp/Temporary ASP.NET Files/root/8847955d/8ce8b26b/DevExpress.Data.v12.2/DevExpress.Data.v12.2.DLL.
LOG: Attempting download of new URL file:///C:/Users/computer/Documents/Visual Studio 2010/Projects/MvcApplication5/MvcApplication5/bin/DevExpress.Data.v12.2.DLL.
LOG: Attempting download of new URL file:///C:/Users/computer/Documents/Visual Studio 2010/Projects/MvcApplication5/MvcApplication5/bin/DevExpress.Data.v12.2/DevExpress.Data.v12.2.DLL.
LOG: Attempting download of new URL file:///C:/Users/computer/AppData/Local/Temp/Temporary ASP.NET Files/root/8847955d/8ce8b26b/DevExpress.Data.v12.2.EXE.
LOG: Attempting download of new URL file:///C:/Users/computer/AppData/Local/Temp/Temporary ASP.NET Files/root/8847955d/8ce8b26b/DevExpress.Data.v12.2/DevExpress.Data.v12.2.EXE.
LOG: Attempting download of new URL file:///C:/Users/computer/Documents/Visual Studio 2010/Projects/MvcApplication5/MvcApplication5/bin/DevExpress.Data.v12.2.EXE.
LOG: Attempting download of new URL file:///C:/Users/computer/Documents/Visual Studio 2010/Projects/MvcApplication5/MvcApplication5/bin/DevExpress.Data.v12.2/DevExpress.Data.v12.2.EXE.
It looks like the DLL versions I have and the ones mentioned on that page are different. Please help.
I ran my project through their project converter which scans your references and web.config files and upgrades the entries to reflect the latest DLL's (if the ones you have are later than the ones you are pointing to in the web.config file), which was the case for me because I just copied the references from that page.
It says you're missing the data assembly. You seem to be using an old version. Download the latest version as there is an empty project template in the DevExpress project wizard.
Also, contact the DevExpress support team and they can help you quicker.
Please take a look at this:
How to: Manually Register DevExpress Extensions to Start Using Them in an MVC Web Application

Assembly binding redirect not working

I am trying to deploy a test web app on Azure, but when I run the Azure emulator on my local machine I get this error from the Azure emulator console attached to my WebRole:
System.TypeLoadException: Unable to load the role entry point due to the following exceptions:
-- System.IO.FileLoadException: Could not load file or assembly 'System.Web.Mvc, Version=3.0.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)
File name: 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
=== Pre-bind state information ===
LOG: User = COLLAB\mirko.lugano
LOG: DisplayName = System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
(Fully-specified)
LOG: Appbase = file:///C:/Code/Application/<MyWebProject>.Azure/csx/Debug/roles/<MyWebProject>/approot/bin
LOG: Initial PrivatePath = C:\Code\Application\<MyWebProject>.Azure\csx\Debug\roles\<MyWebProject>\approot\bin
Calling assembly : ActionMailer.Net.Mvc, Version=0.7.4.0, Culture=neutral, PublicKeyToken=e62db3114c02a1c2.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Code\Application\<MyWebProject>.Azure\csx\Debug\roles\<MyWebProject>\base\x64\WaIISHost.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Attempting download of new URL file:///C:/Code/Application/<MyWebProject>.Azure/csx/Debug/roles/<MyWebProject>/approot/bin/System.Web.Mvc.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
---> System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeModule.GetTypes()
at System.Reflection.Assembly.GetTypes()
at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.GetRoleEntryPoint(Assembly entryPointAssembly)
--- End of inner exception stack trace ---
at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.GetRoleEntryPoint(Assembly entryPointAssembly)
at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.CreateRoleEntryPoint(RoleType roleTypeEnum)
at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.InitializeRoleInternal(RoleType roleTypeEnum)
[fabric] Role state Unknown
Everything had been working fine as long as I had MVC3 installed on my local machine (the MVC3 assembly was in GAC), but since I removed MVC3 (Azure has no MVC installed), I am getting this error. My web app has MVC4 regularly included and that works fine. I had then thought about assembly binding redirection, and I noticed that in my web.config file I already have:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
...
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
...
</assemblyBinding>
</runtime>
which should be already correct, according to the documentation I have read around in internet. I have also tried setting the SpecificVersion property of my System.Web.Mvc.dll (version 4.0.0.0) to false but to no avail. Am I missing something? Shouldn't the calling assembly ActionMailer.Net.Mvc be automatically redirected to the correct version of the MVC assembly? Any ideas are greatly appreciated. Thanks.
In Azure WebRoles, by default (in Full IIS Mode) the RoleEntryPoint gets walled off from the rest of the WebRole, and runs in a different process.
A side effect of this is that your RoleEntryPoint will not have access to your web.config.
Azure SDK 1.3 -1.7 will look in WaIISHost.exe.config
Azure SDK 1.8+ will look in the WebRoleProjectName.dll.config.
With the newest change to the SDK, you should be able to place an app.config in your project and your role entry point should then have access to it.
You can read more about this in this Microsoft blog post or in this Stackoverflow post
Thank you Rune for the precious hint. That didn't solve my problem but it pointed me to the right direction, because I have the latest version of Azure SDK (1.8) and this WaIISHost.exe.config trick no longer works on the latest version of Azure. HERE is stated what I just said and the solution that worked for me, which is to rename the WaIISHost.exe.config file to MyWebAppName.dll.config (placing it at the same level of your web.config file in your web app and setting its Copy to output Directory property to 'Copy Always'. Of course this config file contains the binding redirect section as I described above.
As of today with the latest SDK a WebRoleProjectName.dll.config will be automatically generated for you with the contents of the Web.config and copied to the output directory.
However this won't be automatically be included in the deployment package! For this to happen you have to employ a kind of hackish solution: include the generated file in the project by selecting "show all files", then including just this file. The resulting change in the csproj should look like this (not, don't select it to be "Copy always"!):
<Content Include="bin\WebRoleProjectName.dll.config" />

ASP.NET MVC with Mono

I'm trying to develop an app with ASP.NET MVC Mono.
Installed latest version of Mono and Monodevelop. While trying to run a default "Welcome to ASP.NET MVC on Mono!" app I get the following errors:
Server Error in '/' Application.
Configuration Error
Description: An error occurred during the processing of a
configuration file required to service this request. Please review the
specific error details below and modify your configuration file
appropriately.
Parser Error Message: Could not load file or assembly 'System.Web.Mvc,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or
one of its dependencies. The system cannot find the file specified.
Source Error:
Line 34: Line 35: Line 36: Line 37: Line 38:
Source File: C:\Users\Sergey\Desktop\mvc\mvc\web.config Line: 36
Assembly Load Trace: The following information can be helpful to
determine why the assembly 'System.Web.Mvc, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be loaded.
WRN: Assembly binding logging is turned OFF. To enable assembly bind
failure logging, set the registry value
[HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1. Note: There
is some performance penalty associated with assembly bind failure
logging. To turn this feature off, remove the registry value
[HKLM\Software\Microsoft\Fusion!EnableLog].
Version Information: Microsoft .NET Framework Version:2.0.50727.4927;
ASP.NET Version:2.0.50727.4927
Tried putting System.Web.Mvc.dll from C:\Program Files\Mono-2.10.6\lib\mono\2.0 to bin\ - app still doesn't run, I just get
The located assembly's manifest definition does not match the assembly
reference. (Exception from HRESULT: 0x80131040)
instead of
The system cannot find the file specified.
What should I do?
P.S. My OS is Windows 7.
As suggested in the comment, I'm posting this as an answer ;) When trying to run application which references Mono's assemblies, one can try running it with Mono (not .NET what MonoDevelop does as default) as it uses different GAC.

How can I get a fusion binding log on a host that does not have it enabled?

I'm trying to run an Asp.net MVC 1 app on a host that doesn't support MVC per this post but does support .net 2,3,3.5
However the error message I get back doesn't tell me much:
Server Error in '/assetmanagement' Application.
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: Could not load file or assembly 'TryHTTPHandler' or one of its dependencies. The system cannot find the file specified.
Source Error:
[No relevant source lines]
Source File: D:\Hosting\4582955\html\web.config Line: 65
Assembly Load Trace: The following information can be helpful to determine why the assembly 'TryHTTPHandler' could not be loaded.
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
Version Information: Microsoft .NET Framework Version:2.0.50727.3603; ASP.NET Version:2.0.50727.4049
A google search or stack overflow search for TryHTTPHandler seems to turn up almost nothing.
line 65 of my web.config is as follows:
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ApplicationServices" applicationName="/"/>
I've turned on copy local for System.Web, System.Web.Mvc, System.Web.Routing, and System.Web.Abstractions. I'm not sure how to determine if my host has .net 3.5 or .net 3.5 SP1.
How can I get the binding log or any other idea what's wrong with my configuration? I'm fairly limited on what I can do on the host since it's paid hosting.
If you read the error message closely, it tells you how to enable the fusion log: Since you don't have access to the host registry you'll have to try to reproduce the issue on a machine you do control
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

Resources