Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 559
jao Avatar asked Nov 14 '22 06:11

jao


1 Answers

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.

like image 50
reinder Avatar answered Dec 10 '22 15:12

reinder