繁体   English   中英

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

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

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

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

我们在与本地sqlite数据库文件交互时遇到错误。

“System.InvalidOperationException:实体框架提供程序类型'System.Data.SQLite.EF6.SQLiteProviderServices,System.Data.SQLite.EF6'在ADO.NET提供程序的应用程序配置文件中注册,名称为”System.Data.SQLite“无法加载.EF6'。请确保使用了程序集限定名称,并且该程序集可供正在运行的应用程序使用。有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkId=260882 。 “

使用“Copy Local = true”选项将所有EF dll添加到参考中。 该机器包含.Net framework 4.0。

你能帮我们解决这个问题吗?

问候,

哈日

添加配置文件:

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

刚刚开始使用System.Data.SQLite和Entity Framework进行实验时,我收到了类似的错误消息。 在阅读StackOverflow和博客文章的许多答案后,我决定在此处提供以下信息,希望它可能对遇到类似问题的人有所帮助。

我的配置:

  1. *****。数据 - 项目包含与EF-6相关的代码(DbContext,迁移等); 这个引用了所需的程序集:EntityFramework,System.Data.SQLite,System.Data.SQLite.EF6,System.Data.EF6.Migrations
  2. *****。data.tests - 这个引用了第一个项目;

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

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

就我而言,我决定采用简单的方法。 如果您认为自己需要“终极”解决方案,请参阅自定义MSBuild操作的解决方案: http//www.paraesthesia.com/archive/2014/05/09/recursively-copying-indirect-project-dependencies-in -msbuild.aspx /

有类似的问题。 通过将默认项目从Package Manager Console指向DataAccess项目来修复它,但是为了确保,我还重新启动了VS并进行了重建。 还要确保选择了正确的启动项目(右键单击项目 - >设置为启动项目)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM