简体   繁体   中英

Entity Framework Core and .NET Standard 2.0 - an inconsistent behavior

Environment : VS2019 - ver16.6 , Windows 10 pro 1903

I followed this link from Microsoft team to create a VS2019 solution with .NET Standard 2.0 library project and a dummy .NET Core Console app as a startup project. In that solution, I also followed this EF Core official tutorial to create a SQLite db (called MySQLiteDb.db ) that gets created in the root directory of dummy .NET Core Console .

Afterwards, I referenced that .NET Standard library in one of my WPF Full Framework project to perform some db operations. For that I copied MySQLiteDb.db from the above project into this WPF project and set its Copy to output directory action to Copy if newer with Build Action as None . Now, this WPF Full Framework app works fine and performs multiple db operation on MySQLiteDb.db .

But when I do the same as above on a Microsoft VSTO Add-in project by referencing the same .NET Standard library, I get an inconsistent behavior: For example, half of the time the app successfully performs a data insert but about half of the time the app throws the following error on the data insert. And there is no data validation because this test db has three simple text columns with no unique keys/index etc. Question: Why this inconsistent behavior on VSTO project but not on WPF project while both are .NET 4.8 projects. And how can the issue be resolved?

Error :

Inner Exception 1: SqliteException: SQLite Error 1: 'no such table: MyTable'.

Why this inconsistent behavior on VSTO project but not on WPF project while both are .NET 4.8 projects.

You need to make sure the add-in is using the .net framework 4.0 runtime (CLR) which corresponds to the .net framework 4.8, not CLR 2.0. You can use a configuration file to specify the runtime version to use by the host application, see Application Configuration Files for more information on the runtime element.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM