jao
jao

Reputation: 18620

DbContext crashes with PrimitiveType != null error

Using Entity Framework Code First, the web application crashes on a call to DbContext with the following error:

Assertion failed

Expression: primitiveType != null

Description: Assertion failed: primitiveType != null

It crashes on the following line of code:

public class MyDb : DbContext {

which is called by:

MyDb _db = new MyDb();

So it seams like calling DbContext generates a fatal error. DbContext is an EF function and I cannot debug inside EntityFramework.dll

Upvotes: 5

Views: 1836

Answers (4)

Amol Ahirrao
Amol Ahirrao

Reputation: 62

You need to update your EntityFramework version

Upvotes: -1

andreydruz
andreydruz

Reputation: 110

After installing asp.net4.5 I have same error. The Answer for me is to update Entity Framework to new version.

Deleting "EdmMetaData" table didn't resolve the error.

Upvotes: 1

reinder
reinder

Reputation: 2551

It's a problem related to older versions of EntityFramework. It happens sometimes when copying a Visual Studio Project to a different machine. This can cause the application to calculate a different ModelHash than the one that is in the database (inside the EdmMetaData table). Solution is to delete the EdmMetaData table and use DbDatabase.SetInitializer<MyContext>( new DropCreateDatabaseIfModelChanges<MyContext>()); to put it back in place, or even better: Upgrade to a newer version of EntityFramework that is not utilizing the EdmMetaData table and ModelHashes.

Upvotes: 1

hidden
hidden

Reputation: 3236

I swicth to linq to sql and dint get this error. Dont know what entities is doing to cause this.

Upvotes: 0

Related Questions