2

I've upgraded MVC3 from RC2 to RTM. We were using Ninject 2.1.0.76, but things stopped working once I upgraded. So I used the NuGet manager to get the latest Ninject, Ninject.MVC3 and Ninject.Web.Mvc libraries (2.1.0.91, 1.0.0.0 and 2.1.0.39 respectively). Now, it creates an AppStart_NinjectMVC3 file.

I removed NinjectHttpApplication from my global.asax and made it back into a regular HttpApplication. When I tried to build, I get;

"Exception has been thrown by the target of an invocation"

Looking further, if I disable the following line;

DependencyResolver.SetResolver(new NinjectServiceLocator(kernel));

The build goes through. But I'm pretty sure I don't want to do this.

Any ideas?

----- UPDATE ---------

I created a new MVC3 project, added the reference to Ninject.MVC3 and this builds and runs fine. I compared web.config, don't see any differences that relate to Ninject or MVC in the two. A fresh project doesn't add the Ninject.Web.Mvc library, so I removed it and commented out all code relating to that, and still, the error occurs.

1
  • Do you get a runtime or a compile-time error? Jan 24, 2011 at 15:24

2 Answers 2

1

Since ASP.NET MVC 3 Beta the IServiceLocator interface is replaced by IDependencyResolver. I'm not sure Ninject.MVC3 already has a release where they have implemented this interface.

Judging from the line DependencyResolver.SetResolver(new NinjectServiceLocator(kernel)) it appears they have not.

Here's a simple implementation of this interface for Ninject.

UPDATE: The Ninject.Web.Mvc library has a NinjectDependencyResolver class that extends from the IDependencyResolver interface. I think you should use this one (I do and everything works fine).

5
  • If I look at the object browser for the ServiceLocator, the base type shows as IDependencyResolver. I tried swapping out the locator with the sample implementation, but get the same issue. Jan 24, 2011 at 15:06
  • I've changed this out, but I'm still getting the issue. So this is looking like a configuration problem. The sample project I started had 2.1.0.76 of Ninject, no Ninject.Web.Mvc and Ninject.MVC3 1.0.0.0. This builds fine. All projects in my solution have 2.1.0.91, and I've tried swapping back out but no luck. Jan 24, 2011 at 15:26
  • You may want to check that the Ninject libraries have a dependency on the correct MVC library (version 3 RTM) and not on an older version. Jan 24, 2011 at 15:40
  • So, I checked Ninject.MVC3, dependency on 2.1.0.76. So, I removed .91, removed ninject.web.mvc .39 (because that was built against .91), added in Ninject.76 and ninject.web.mvc .20. I now lose the NinjectDependancyResolver (seems that was added in .39) and I'm back to the same issue. Jan 24, 2011 at 16:48
  • As Remo Gloor suggests, I don't think you need the Ninject.MVC3 library. I have never used it, although the name suggests you need it. Just use Ninject.Web.Mvc, use the NinjectDependencyResolver class that's in there and everything should work fine. Jan 24, 2011 at 18:23
1

Download the dlls from here

https://github.com/ninject/ninject/archives/master

https://github.com/ninject/ninject.web.mvc/archives/master

Further more do not use Ninject.MVC3 all you need ist Ninject.Web.Mvc

I also have an article documenting same here

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.