mardi 26 janvier 2016

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

I am trying to port an application from EF4 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://ift.tt/1eigFsq -->
  </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 = @"http://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?

Aucun commentaire:

Enregistrer un commentaire