Strange compilation error in Entity Framework and MVC application
I've just created a new MVC 2 application that references both an entity model library and a services library, and all compiles fine without running the app, but when I try running it, I get the following runtime error"
Compiler Error Message: CS0012: The type 'System.Data.Objects.DataClasses.EntityObject' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyTok开发者_开发知识库en=b77a5c561934e089'.
I have double checked umteen times (e.g. Umpteen*n) and the cited assembly is refenced in all three projects. If it wasn't, WTF would I not get a build error?
For ASP.NET MVC 4 (.NET4.5) change from
<system.web>
<compilation debug="true" targetFramework="4.0" />
...
To
<system.web>
<compilation debug="true" targetFramework="4.0" >
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</assemblies>
</compilation>
Just ran into this. Basically you need to add a reference to System.Data.Entity
within your web.config
(And make you have added the dll as a reference to the project too)
For .NET3.5
<assemblies>
..........
<add assembly="System.Data.Entity, Version=3.5.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089"/>
</assemblies>
For .NET4
:
<assemblies>
..........
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089" />
</assemblies>
I think it is answered here: Is the combination of ADO.NET Entity Framework and ASP.MVC wrong by any chance?
Try with Adding References of System.Data.Entity
in your current project which is giving error.
In my case, my web project (targeting .net v4.5) had a dependency on another project containing EDMX models (targeting .net v4.0).
Once I upgraded the dependency project to target .net 4.5 and rebuilt this error went away.
Closing Visual Studio and reopening it again was enough to do the trick. As a note, I made recent changes to the edmx model.
精彩评论