Adding Ninject.MVC3 to existing MVC(4) project
Asked Answered
W

2

9

I am working on a project with MVC4, and have decided that I wish to add some dependency injection via Ninject. After download/install via NuGet, I find this error in the NinjectWebCommon.cs (Line 23):

The type 'System.Web.IHttpModule' is defined in an assembly 
that is not referenced. You must add a reference to assembly 
'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

and then a bit later (line 44):

The type or namespace name 'IHttpModule' could not be found 
(are you missing a using directive or an assembly reference?)

I expect that this Normally works, but that I've done something that doesn't work when adding Ninject to the project after the fact.

Edit: The above errors are only thrown by the test project....

Wagers answered 29/5, 2012 at 13:56 Comment(1)
I am not aware of any way in which it is not.Wagers
P
22

Make sure you specify the System.Web reference in both the main and test project. The test projects have their own list of references to maintain. I expect you don't have System.Web in the test project.

Pivoting answered 29/5, 2012 at 16:37 Comment(3)
Ugh...that was it...so simple facepalmWagers
I don't understand why the reference in the test project affects the NinjectWebCommon.cs file when it's in a different project within the solution... I had the reference within my 'Models' and 'MVC' projects within my solution. Adding the reference to the test project did work though :)Placido
Yep, I opened up my Project.Test and went to add reference > Assemblies > System.Web. Checked it, added it and no more errors!Expectoration
K
0

Make sure Ninject didn't add web references to your model project.

Kwan answered 9/3, 2013 at 13:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.