efcore: Could not set up parent class after update to EFCore 3.1

I tried updating my project from EFCore 2.2 to EFCore 3.1. I also configured all my GUIDs to continue writing into BLOB, because I want to wait if EFCore 5 might change this base type again.

Compiling the project is not an issue. I was also able to create a new Migration (that gave me all GUIDs as changes, even if they already were BLOBs, but I deleted that unnecessary change).

Unfortunatly I am not able to start the App on Android anymore. I always get the following Error in one of my first lines:

Could not set up parent class, due to: Parent class vtable failed to initialize, due to: VTable setup of type Microsoft.EntityFrameworkCore.DbContext failed assembly:/storage/emulated/0/Android/data/com.MehrData.mdsMobileClient/files/.__override__/Microsoft.EntityFrameworkCore.dll type:DbContext member:(null) assembly:/storage/emulated/0/Android/data/com.MehrData.mdsMobileClient/files/.__override__/mdsMobileClient.Core.dll type:BaseContext member:(null)

StackTrace

  at mdsMobileClient.App..ctor () [0x00032] in C:\SVN\mdsmobile\mdsMobileClient\mdsMobileClient\mdsMobileClient\mdsMobileClient\App.xaml.cs:34 
  at mdsMobileClient.Droid.MainActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x000a8] in C:\SVN\mdsmobile\mdsMobileClient\mdsMobileClient\mdsMobileClient\mdsMobileClient.Android\MainActivity.cs:47 
  at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x00011] in <4a189ea3b82b48a089ac9002b2abc206>:0 
  at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.8(intptr,intptr,intptr)

App.xaml.cs:34 calls my App init method. Within this method I create a first Context and therefore trigger the configuration.

Context = new Core.Context.LocalContext(GetDatabaseFileName());

My database initialization:

private void Init(string path)
    {
      _dbPath = path;
      try
      {
        SQLitePCL.Batteries_V2.Init();
        SQLitePCL.raw.sqlite3_config(2 /*SQLITE_CONFIG_MULTITHREAD*/);
        Database.Migrate();
      }
      catch (Exception ex)
      {
        //AppCenter Reporting
      }
    }

In my project I use a BaseContext, that derives from DbContext, to define everything that is the same on the Cloud (.netCore) and on the app. The App itself uses a LocalContext that derives from BaseContext and adds all the SQLite specific stuff and some definitions that are app specific.

I haven’t found anything online about this issue, but some old incompatibility issues. I had an SQLite-PCL nuget installed, which I removed after reading it was incompatible and most likely not needed since I get the SQLite functions through EFCore.

I have deactivated the linker entirely, because I got another error I didn’t put time into solving yet. I updated to the latest Xamarin.Forms and switched my projects to .netStandard 2.1.

Does anyone have an idea what the issue could be? Other than the definition of all GUIDs and the update to EFCore I did not change anything at first. I’m not sure if this is really a problem from EFCore or if something else is the core of the issue, but right now I have no idea where to look for a solution to this.

Further technical details

EF Core version: 3.1. Database provider: Microsoft.EntityFrameworkCore.Sqlite Target framework: .netStandard 2.0 / 2.1 , Xamarin.Forms 4.4 Operating system: Windows 10 Pro 18363 IDE: Visual Studio 2019 16.4.5

EDIT: Changed the database provider. I’m using Sqlite of course, not SqlServer

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 19 (8 by maintainers)

Most upvoted comments

You can leave Batteries.Init code in everywhere–it won’t do any harm. We might need a project to dig into this. Also, are you using the latest Xamarin tools?