错误 - 无法加载不变名称为“System.Data.SQLite.EF6”的ADO.NET提供程序

3

我们有一个使用VS2013和EF6准备的应用程序。

它在所有机器上都能正常工作,但在某台机器上无法正常工作。

与本地sqlite数据库文件交互时,我们遇到以下错误:

"System.InvalidOperationException: 在应用程序配置文件中为ADO.NET提供程序注册的Entity Framework提供程序类型'System.Data.SQLite.EF6.SQLiteProviderServices,System.Data.SQLite.EF6'的不变名称为'System.Data.SQLite.EF6'。无法加载,请确保使用程序集限定名称并且该程序集可用于运行的应用程序。请参见http://go.microsoft.com/fwlink/?LinkId=260882获取更多信息。"

所有的EF dll都已添加到引用中,并选择了“复制本地=true”的选项。该机器包含.Net框架4.0。

请帮助我们解决这个问题。

谢谢,

Hari

添加配置文件:

<?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>

添加了两个独立的行(注释提到合并这两行):

<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" />

请说明我们是否需要提到 invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6"。

展示你的 app.config/web.config。检查 SQLite 提供程序实例是否已经注册:<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6"/> - Tetsuya Yamamoto
2个回答

0

遇到了类似的问题。通过将默认项目从包管理器控制台指向DataAccess项目来解决它,但为了确保,我还重新启动了VS并进行了重建。还要确保选择了正确的启动项目(右键单击项目->设置为启动项目)。


0

当我刚开始使用System.Data.SQLite和Entity Framework进行实验时,我遇到了类似的错误信息。在阅读了StackOverflow上的许多答案和博客文章后,我决定将下面的信息放在这里,希望它对遇到类似问题的人有所帮助。

我的配置:

  1. *****.data -- 该项目包含EF-6相关代码(DbContext、迁移等);它引用了必需的程序集:EntityFramework、System.Data.SQLite、System.Data.SQLite.EF6、System.Data.EF6.Migrations
  2. *****.data.tests -- 它引用了第一个项目;

由于某种原因,在构建第二个项目时,System.Data.SQLite.EF6程序集没有被复制到输出目录中。

互联网提供了许多解决方法--从向第二个(主机)项目添加缺少依赖项的引用到使用自定义MSBuild操作递归复制所有依赖项。

在我的情况下,我决定采用简单的方法。如果你觉得需要“终极”解决方案,这里有一个涉及自定义 MSBuild 操作的解决方案:http://www.paraesthesia.com/archive/2014/05/09/recursively-copying-indirect-project-dependencies-in-msbuild.aspx/

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接