Tip #1: Understanding Cryptic MVC Errors

Some who try to use the Entity Framework with MVC may encounter the following error:

CompileError

If you can see it the error reads:
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=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

I spent a good deal of time trying to add this reference to the View. However, for some reason despite I had the assembly in my Reference folder in the Project, it was not in the web.config.  Add the following line to the web.config:

<add assembly="System.Data.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

Once you add this and rebuild, the error should go away.

13 thoughts on “Tip #1: Understanding Cryptic MVC Errors

  1. My co-worker solved this. If you think that you should not be adding reference to System.Data.Entity then you should not.
    The problem might be the ObjectQuery Extensions that you might have used down Database Layer, now since extensions are Static; all LinQ queries takes benefit of those and it causes the build to fail everywhere you have used linQ queries. So make sure your Object extensions are necessary and needed..

    Like

  2. For me, I was getting this error in code in Tests. I had to add a reference to System.Data.Entity there (right click .Tests, Add Reference, .NET, System.Data.Entity).

    Like

Leave a comment