Tuesday, October 14, 2008

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"/>

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

11 comments:

snowman said...

Thanks, this solved my problem.

jabbasoft said...

Thankyou! fixed me too

Anonymous said...

You just saved me hours. Thanks!

Anonymous said...

Thanks!

Anonymous said...

Thanks mate, good call.

oo said...

Spend hours chasing this one :( Thanx mate!

Anonymous said...

thanks..solved my problem

Томислав Марковски said...

I love you!

Anonymous said...

coool !! thanks !!!

Martin Evans said...

Lifesaver! Thank you.

Akshay Shah said...

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..