user3215105
user3215105

Reputation: 73

Error - ADO.NET provider with invariant name 'System.Data.SQLite.EF6' could not be loaded

We have an application which was prepared using VS2013 with EF6.

It is working fine in all the machines but in one machine it is not working.

We are getting below error while interacting with local sqlite database file.

"System.InvalidOperationException: The Entity Framework provider type 'System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SQLite.EF6' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information."

All the EF dll are added to the reference with "Copy Local = true" option. The machine contains .Net framework 4.0.

Could you please help us to resolve the issue.

Regards,

Hari

Adding configuration file:

<?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 -->
    <!-- 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.0" />
  </startup>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
  </startup>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" />
  </startup>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v13.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
    </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" />
    </DbProviderFactories>
  </system.data>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System" publicKeyToken="b77a5c561934e089" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Data" publicKeyToken="b77a5c561934e089" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Configuration" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Xml" publicKeyToken="b77a5c561934e089" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Core" publicKeyToken="b77a5c561934e089" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Management" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.4.0.0" newVersion="4.4.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <DbProviderFactories>
    <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>  
<connectionStrings><add name="xxxx" connectionString="metadata=res://*/Entities.xxxx.csdl|res://*/Entities.xxxx.ssdl|res://*/Entities.xxxx.msl;provider=System.Data.SQLite.EF6;provider connection string=&quot;data source=C:\Users\Public\Documents\xxxx\xxxx\xxxx_Data.db3&quot;" providerName="System.Data.EntityClient" /></connectionStrings></configuration>

Two separate line is added (Comment mentioning to merge two lines):

<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />

<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />

Please clarify whether we need to mention

invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6"

Upvotes: 3

Views: 4869

Answers (2)

Watth
Watth

Reputation: 446

Got similar problem. Fixed it by pointing the default project from Package Manager Console to the DataAccess project, but just to be sure, I've also restarted VS and did a rebuild. Also make sure that you have the correct Start Up project selected (right-click on project ->Set as Start Up project).

Upvotes: 0

Alexey Adadurov
Alexey Adadurov

Reputation: 184

I got similar error message when I have just started experiments with System.Data.SQLite & Entity Framework. After reading many answers on StackOverflow and blog posts, I decided to put the below information here hoping it may turn out to be helpful to someone running into a similar issue.

My configuration:

  1. *****.data -- the project contains the EF-6 related code (DbContext, migrations etc.); this one references the required assemblies: EntityFramework, System.Data.SQLite, System.Data.SQLite.EF6, System.Data.EF6.Migrations
  2. *****.data.tests -- this one references the 1st project;

for some reason, when building the 2nd project, the System.Data.SQLite.EF6 assembly is not copied to the output directory.

The Internet offers multitude of workarounds -- from adding reference to the missing dependency to the 2nd (host) project to using a custom MSBuild action to copy all the dependencies recursively.

In my case, I decided to go with the simple approach. If you feel you need the 'ultimate' solution, here is the solution involving a custom MSBuild action: http://www.paraesthesia.com/archive/2014/05/09/recursively-copying-indirect-project-dependencies-in-msbuild.aspx/

Upvotes: 0

Related Questions