c# - 仅当我以 RELEASE 模式发布时,EntityFramework.SqlServer.dll 才不会添加到发布的文件夹中

标签 c# entity-framework-6

我知道 EF6 EntityFramework.SqlServer 存在问题,并且在上下文构造函数中包含 var type = typeof(System.Data.Entity.SqlServer.SqlProviderServices);。当我在 DEBUG 模式下发布时它工作正常。

仅当我以 RELEASE 模式发布时才会出现以下错误。原因是发布的文件夹中缺少 EntityFramework.SqlServer.dll。但是,bin 文件夹中有用于调试和 Release模式的 EntityFramework.SqlServer.dll。

错误:

The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application.

为什么只有当我使用 RELEASE 模式发布时它才丢失?

最佳答案

不知道为什么;但是将此方法添加到您的上下文将使您的项目复制 dll

private void FixEfProviderServicesProblem()
        {
            // The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer'
            // for the 'System.Data.SqlClient' ADO.NET provider could not be loaded. 
            // Make sure the provider assembly is available to the running application. 
            // See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
            var instance = System.Data.Entity.SqlServer.SqlProviderServices.Instance;
        }

测试和工作 引用:Entity Framework Provider type could not be loaded?

关于c# - 仅当我以 RELEASE 模式发布时,EntityFramework.SqlServer.dll 才不会添加到发布的文件夹中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25433298/

相关文章:

c# - 如何取消await Task.Delay()?

c# - 静态类的线程安全

c# - 无法将类型为 'RSACng' 的对象转换为类型 'System.Security.Cryptography.RSACryptoServiceProvider'

c# - 在 SQLite 中将 "String"存储为 "TEXT"而不是 "VarChar"- WP8

c# - EF 枚举所有被忽略的属性

c# - 插入后获取实体导航属性

c# - Entity Framework 代码优先 Fluent API

c# - 在 C# 中设置默认字体

c# - 无法确定类型为 "System.Data.Sqlite.SqliteFactory"的提供程序工厂的提供程序名称

entity-framework - 与 Code First 的一对多递归关系