I am trying to learn ASP.NET MVC with Adam Freeman's "Pro ASP.NET MVC 5" book. Unfortunately all projects using Ninject throw the same error
An exception of type 'System.IO.FileLoadException' occurred in Ninject.dll but was not >handled in user code
Additional information: 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)
This is exactly the same problem which was discussed in this thread,
Issues after installing ninject mvc 3 in mvc 5 project
but the offered solutions don't work for me.
I have tried target platforms 4.5 and 4.5.1, Ninject MVC3 and MVC5. I have also inserted this snippet
<runtime>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
</runtime>
in the Web.config file, without any effect.
Problem must be in the Ninject MVC3 and MVC5 packages. Whenever these packages are installed, any call to Ninject.StandardKernel() throws the exception, regardless if made from the Global.asaxor the new NinjectWebCommon.cs or from any other piece of code (of course, this should not matter for this kind of exception anyway, but in this thread Error using Ninject with ASP.NET V4 it was suggested that the error might have something to do with using the Global.asax for connecting Ninject to the application).
I have run out of ideas. Can anyone help?
Add to your Web.config (i.e. SportsStore.WebUI project):
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
It should work with this -> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
Related
We have migrated from TFS 2010 to TeamCity and we have issues in building our solution file.
We are using .NET 4.0.
Google library is notoriously causing issues with .NET 4.0 + system.net.http when trying to build it.
We managed to get this setup working on TFS(it uses MSBuild 4.0) without errors.
App.config should have correct assemblybindings:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.9.0" newVersion="2.6.9.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.9.0" newVersion="2.6.9.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.2.28.0" newVersion="2.2.28.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.2.28.0" newVersion="2.2.28.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
We have already tried:
- Use different runner types: Visual studio, MSbuild
- Referenced all Dlls directly(google+system.net.http+etc.)
- Use straight Nuget Package restore on these DLLs(it restores everything ok)
Build error is:
ResolveAssemblyReference] C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(1635, 5): warning MSB3268: The primary reference "Google.Apis.Auth.PlatformServices, Version=1.9.0.26016, Culture=neutral, processorArchitecture=MSIL" could not be resolved because it has an indirect dependency on the framework assembly "System.Net.Http, Version=2.2.22.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "Google.Apis.Auth.PlatformServices, Version=1.9.0.26016, Culture=neutral, processorArchitecture=MSIL" or retarget your application to a framework version which contains "System.Net.Http, Version=2.2.22.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
Followed by:
[07:58:29]W: [MSBuild output] C:\BuildAgent\work\dda43f1992063b18\Integrations\CalendarSync\Devices\Google Calendar\GoogleCalendarDevice.vb(788,78): error BC30009: Reference required to assembly 'Google.Apis, Version=1.9.0.23042, Culture=neutral, PublicKeyToken=null' containing the implemented interface 'Google.Apis.Requests.IDirectResponseSchema'. Add one to your project. [C:\BuildAgent\work\dda43f1992063b18\Integrations\CalendarSync\Severa.Integrations.CalendarSync.vbproj]
We now have non optimal solution to the problem.
MsBuild finds wrong version from one of these locations:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0
C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Packages\Microsoft.Net.Http.2.0.20710.0\lib\net40
C:\Program Files (x86)\Microsoft Web Tools\Packages\Microsoft.Net.Http.2.0.20710.0\lib\net40
This is wrong since the version in these locations is: 1.0.0.0.
If we replace all these places with 2.2.28 version it works..
We have tried following:
Compliation.config add assembly
Web.config bindingredirect
Sln file hints to right packages..
Unfortunately our TC agents are in shared environment so we can't replace this files in all these locations.
Any ideas?
I am running a webapi and getting the following error,
{
"Message": "An error has occurred.",
"ExceptionMessage": "Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.",
"ExceptionType": "System.IO.FileNotFoundException",
"StackTrace": null
}
I am running on MVC4, VS.NET 2012 locally with no problem, and in my web.config, I've also redirected
<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>
I have other web api but it's running fine, this is the only one giving me problem, nothing special in the method either. Any idea or similar experience?
Locally - my MVC 4, asp.net, c# app runs fine on IIS 8 / Windows 8.
When deployed to Windows Server 2008, I get this error:
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)
and
[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)]
Elmah.Mvc.Bootstrap.Initialize() +0
[InvalidOperationException: The pre-application start initialization method Initialize on type Elmah.Mvc.Bootstrap threw an exception with the following error message: 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).]
System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures) +12881963
System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +12881672
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath) +240
System.Web.Compilation.BuildManager.ExecutePreAppStart() +152
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +1151
[HttpException (0x80004005): The pre-application start initialization method Initialize on type Elmah.Mvc.Bootstrap threw an exception with the following error message: 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).]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12881108
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12722297
This happens if I select 'Only files needed to run this application' from the 'Items to deploy' drop down in project properties/package/publish web.
If I select 'all files in this project' it works fine.
I guess Elmah is reliant on an older version of MVC or something - how can I fix this without having to upload all the files?
Whats the best way to problem solve situations like this?
Thanks.
I had this exact same issue using MVC4 with Ninject built for .Net 4.5
To fix this i had to add a binding redirect to my Web.config file:
(at the end of the file, just before the </configuration> tag)
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
This forces the web server to use System.Web.Mvc 4.0.0.0 instead of an older version.
<dependentAssembly>
***<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-5.2.7.0"*** newVersion="5.2.7.0" />
</dependentAssembly>
Check correct versions are there
To install System.Web.Mvc 3.0.0.0 version
1) Install windows web platform installer
2) Open Windows web platform installer from start menu
3) Go to Products tab
4) Search for MVC
5) Install MVC 3
There are some procedures using to fix the issue and if the binding redirect in web.config does not solve the problem, you can try the following steps to fix it:
1) In Visual Studio Solution Explorer tree right-click References under your web project and select Manage NuGet Packages.
2) Go to Browse tab and select nuget.org as Package source.
3) Search and install the following packages: Ninject, Ninject.Web.Common and Ninject.MVC5.
It is also better to update the packages particularly Microsoft ASP.NET MVC on Updates tab of Manage NuGet Packages.
In the error page I had this:
LOG: Redirection detected in the application configuration file: 5.1.0.0 was redirected to 5.2.3.0.
So I had to change this line in the web.config to the 5.1.0.0 version and it worked!
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.1.0.0" />
<!--<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" /> Older line -->
</dependentAssembly>
I think this is due to a version problem when I downloaded the code from TFS
Hope this helps
Add below code in web.config:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.1" />
</dependentAssembly>
</assemblyBinding>
I'm creating a new MVC 4 website, and I'd like to use the Unity.MVC3 library to integrate with the DependencyResolver stuff built into MVC.
I also want to reference some data-access DLLs from an older, much larger project.
My problem is that Unity.MVC3 and the older DLLs are compiled against different versions of Unity, 1.2.0.0 and 2.1.505.0, respectively. I tried creating a binding redirect in my web.config file like so:
<dependentAssembly>
<assemblyIdentity name="Microsoft.Practices.Unity" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersions="1.2.0.0-2.1.505.0" newVersion="2.1.505.0" />
</dependentAssembly>
However, I still get the following error:
Could not load file or assembly 'Microsoft.Practices.Unity, Version=1.2.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 turned on assembly binding logging, and the last two lines state:
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
Why isn't my binding redirect being respected? Is there a way to override its checking for major version conflicts?
There is a typo in the key token:
<assemblyIdentity name="Microsoft.Practices.Unity"
publicKeyToken="31bf856ad364e35" />
should be:
<assemblyIdentity name="Microsoft.Practices.Unity"
publicKeyToken="31bf3856ad364e35" />
Binding redirect does not complain in case of typos, it just does nothing.
I've made a test application, with this configuration it works:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Practices.Unity" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.2.0.0" newVersion="2.1.505.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Pay attention to xmlns, without it, it fails silently.
I have been trying out the DotNetOpenAuth samples with ASP.Net MVC 4 Developer Preview.
I can successfully invoke my Action from my test page, but run into a strange issue because of one line of code:
var request = _openid.CreateRequest(openIdUrl);
var fetch = new FetchRequest();
fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
fetch.Attributes.AddRequired(WellKnownAttributes.Name.First);
fetch.Attributes.AddRequired(WellKnownAttributes.Name.Last);
request.AddExtension(fetch);
//return RedirectToAction("Login");
return request.RedirectingResponse.AsActionResult(); // <-- This is the line throwing the error
If I comment out the offending line of code and uncomment the one before this, I do not see the runtime error anymore.
So far I have tried:
1) Ensuring that I have the correct redirects:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
</dependentAssembly>
</assemblyBinding>
<legacyHMACWarning enabled="0" />
</runtime>
2) Have the correct namespaces:
using DotNetOpenAuth.OpenId.Extensions.AttributeExchange;
using DotNetOpenAuth.OpenId.Extensions;
It seems to me that the DotNetOpenAuth dll was compiled against MVC V 1.0.0 and the binding redirect is either not working or the extension method was maybe working against a deprecated method.
MVC Version: 4.0.0.0
DotNetOpenAuth Version: 3.4.7.11121
Any help on getting this working with MVC 4 would be greatly appreciated.
The MVC error screen image is further below:
Image of Error Screen
Update
I found that AsActionResult is the cause of the issue, maybe because the extension method is not compatible with .Net 4.0. I can get the OutgoingWebResponse object from request.RedirectingResponse but do know how to cast it to an ActionResult
It appears your binding redirects are corrupted. Notice how System.Web.Mvc appears twice? Try removing the second one as the first one looks correct.
Yes, DNOA is built against MVC 1.0, and this is by design so that it works against all versions of MVC (given the appropriate redirects). This is purely an MVC version thing -- not a .NET 4.0 thing.