简体   繁体   中英

System.Data.SQLite ADO.NET Provider cannot be loaded on non development machine

I am trying to port an application from EF3.5 using MS-SQL Server to EF6 using SQLite. Currently the application runs fine on my development machine but as soon as I try to deploy it somewhere else (in this case my Installation-Test-VM), it won't load. Instead I get an exception stating that the ADO.NET Provider with the invariant name 'System.Data.SQLite' and the framework provider type 'System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6' could not be loaded.

I get the exception in german, the original text is

Der in der Anwendungskonfigurationsdatei für den ADO.NET-Anbieter mit dem invarianten Namen 'System.Data.SQLite' registrierte Entity Framework-Anbietertyp 'System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6' konnte nicht geladen werden.

I get the same message on the development machine when I remove the SQLite DLLs (System.Data.SQLite.dll and System.Data.SQLite.EF6.dll) from the output directory.

My config file looks like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
  </startup>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="EntityFramework.MappingAPI" publicKeyToken="7ee2e825d201459e" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.9" newVersion="6.0.0.9" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <entityFramework>
    <providers>
      <provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
      <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <system.data>
    <DbProviderFactories>
      <remove invariant="System.Data.SQLite.EF6" />
      <add name="SQLite Data Provider (Entity Framework 6)" 
           invariant="System.Data.SQLite.EF6" 
           description=".NET Framework Data Provider for SQLite (Entity Framework 6)" 
           type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />
      <remove invariant="System.Data.SQLite" />
      <add name="SQLite Data Provider"
                           invariant="System.Data.SQLite"
                           description=".NET Framework Data Provider for SQLite"
                           type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
    </DbProviderFactories>
  </system.data>
</configuration>

The connection is build at runtime like this:

EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder();
entityBuilder.Provider = "System.Data.SQLite"; //I also tried System.Data.SQLite.EF6, same result
entityBuilder.ProviderConnectionString = new SqlConnectionStringBuilder()
{
    DataSource = "sqlite_master.db" //The idea is that the user will later be able to choose which DB to open via a file chooser
}.ConnectionString;
entityBuilder.Metadata = @"res://*/OTDModel.csdl|res://*/OTDModel.ssdl|res://*/OTDModel.msl";
connection = new EntityConnection(entityBuilder.ToString()); //here the exception is thrown
connection.Open();
classThatExtendsDbContext dbContext = new classThatExtendsDbContext(connection);

Both DLLs have Local Copy = True and Specific Version = False set in Visual Studio.

I've also tried to use 32bit DLLs on the VM (VM runs a 32bit Win7, dev machine runs 64bit) from the sqlite-netFx451-binary-bundle-Win32-2013-1.0.99.0 paket. Same result.

Has anyone an idea what could be the cause of that behaviour and how to fix this?

UPDATE

I've dusted off an old development machine which has never been used with SQLite and happens to run Windows 7 64Bit. The application starts without any problem. Now I'm setting up a 64bit VM to see if my problem is limited to 32bit machines.

UPDATE 2

Using a 64Bit VM doesn't work as well. Same error as usual.

I've now managed to fix the problem.

The solution is to manually install the correct Microsoft Visual C++ Runtime Library from https://support.microsoft.com/kb/2019667

This helped on both the 32 and the 64bit VM. I used the 2013-x86 version but I guess that you'd have to use the x64 one, if you compile a 64bit application.

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