简体   繁体   中英

An exception of type 'System.IO.FileLoadException' occurred in Ninject.dll but was not handled in user code

I am following the Pro ASP.Net MVC5 book by Adam Freeman. I have created the sportsStore project as per the chapter 7. And after creating the project templates and adding the references, I build the project and try to debug it. I get this pop-up box 在此处输入图片说明

And if I click on cancel, I get the exception mentioned in the question. I am not able to figure this out. Any suggestions

在此处输入图片说明

I get the above error when I click on cancel.

Here is the call stack of the exception -

Ninject.dll!Ninject.Modules.AssemblyNameRetriever.GetAssemblyNames(System.Collections.Generic.IEnumerable<string> filenames, System.Predicate<System.Reflection.Assembly> filter) Line 54   C#
Ninject.dll!Ninject.Modules.CompiledModuleLoaderPlugin.LoadModules(System.Collections.Generic.IEnumerable<string> filenames) Line 81    C#
Ninject.dll!Ninject.Modules.ModuleLoader.LoadModules(System.Collections.Generic.IEnumerable<string> patterns) Line 54   C#
Ninject.dll!Ninject.KernelBase.Load(System.Collections.Generic.IEnumerable<string> filePatterns) Line 237   C#
Ninject.dll!Ninject.KernelBase.KernelBase(Ninject.Components.IComponentContainer components, Ninject.INinjectSettings settings, Ninject.Modules.INinjectModule[] modules) Line 100  C#
Ninject.dll!Ninject.KernelBase.KernelBase(Ninject.Modules.INinjectModule[] modules) Line 60 C#
Ninject.dll!Ninject.StandardKernel.StandardKernel(Ninject.Modules.INinjectModule[] modules) Line 48 C#

SportsStore.WebUI.dll!SportsStore.WebUI.App_Start.NinjectWebCommon.CreateKernel() Line 38 C# Ninject.Web.Common.dll!Ninject.Web.Common.Bootstrapper.Initialize(System.Func createKernelCallback) Line 50 C# SportsStore.WebUI.dll!SportsStore.WebUI.App_Start.NinjectWebCommon.Start() Line 23 C# [External Code] . I understand that the AssemblyNameRetriever class is missing and I did try to fix it by downloading it from github and using that class. But again it gives some exceptions. Shouldn't the Ninject take care of this class by itself.

Looking at your exception, you are trying to load Mvc Version 3.0.0.0 . You are currently running a different Mvc version.

If you have the source code to the projects that depend on the older Mvc version, you can try to re-compile them with the newer version. You can also try messing with the dependencies to have the right version across the board.

There is also a code project page with a person with a similar situation. The author writes :

After reviewing the code pes1957 sent to me I was able to determine that there was indeed an assembly reference error.

Basically the number of projects that were in the solution had a mixture of version 5 and 6 Entity Framework references. I updated the references, and web.config to show the correct version number and all compiles correctly.

The same problem occured in my project. It seems that installing NInject from nuget package as first one caused the Ninject library wants System.Web.MVC v3. After uninstalling all Ninject library from nuget package manager and adding NInject.MVC5 package as the first and only package, the problem was solved.

I came across this issue and turned out my MVC web project was referencing another MVC Web API project, Ninject error was coming from the Web API project. In my case I removed the reference to keep things simple.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM