1

I've created a .NET Standard 2.0 class library project that works fine when referenced by a WPF App (.NET Framework 4.8) project. But when the same library is referenced by a MS Office VSTO Project (also using .NET Framework 4.8), I get the following error on the code line shown below:

Remarks:

  1. I'm using VS2019, Windows20 Pro, Microsoft.Data.Sqlite and following example from same link.
  2. Exact same code works fine on WPF app.
  3. I also tried installing SQLitePCLRaw.core package (as mentioned in the error) but still the same error. Although, I think I should not have to install this package since I did not have to do it with WPF app.
  4. Same copies of MySQLiteDb.db file reside in the bin\Debug folder of VSTO as well as WPF folder. So, that should probably not be an issue

Error:

FileLoadException: Could not load file or assembly 'SQLitePCLRaw.core, Version=2.0.2.669, Culture=neutral, PublicKeyToken=1488e028ca7ab535' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Code [error occurs at line using (SqliteConnection db = ....):

string SQLiteDbpath = System.IO.Path.Combine(GetAppInstalPath, "MySQLiteDb.db");

using (SqliteConnection db = new SqliteConnection($"Filename={SQLiteDbpath}"))
{
    db.Open();

    using (SqliteCommand insertCommand = new SqliteCommand())
    {
        ......
        insertCommand.ExecuteNonQuery();
    }
}
nam
  • 21,967
  • 37
  • 158
  • 332

1 Answers1

0

FileLoadException: Could not load file or assembly 'SQLitePCLRaw.core, Version=2.0.2.669, Culture=neutral, PublicKeyToken=1488e028ca7ab535' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

You need to include the missed file (SQLitePCLRaw.core) to the folder with the add-in files.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • As mentioned in `item 3` of my `Remarks` above, I already tried installing it but still the same error. If you look at this [official tutorial](https://learn.microsoft.com/en-us/windows/uwp/data-access/sqlite-databases#the-minimum-version-of-your-project-targets-the-fall-creators-update) you will get an idea of what packages get installed on which project (the main project and the .NET Standard project). The only difference between that tutorial and mine is that they are using `Microsoft.Data.Sqlite.Core` (because their main project is UWP) and I'm using `Microsoft.Data.Sqlite` – nam May 31 '20 at 20:50