c# - 使用 EntityFramework 源项目而不是其程序集的解决方案无法成功启动

标签 c# entity-framework configuration .net-4.0 app-config

我有一个 WinForm 项目,它使用 EntityFramework 6.1.2-beta.NET4,它运行良好,直到我决定将 EF 程序集替换为其源代码,以实现某些跟踪目标,因此我从项目引用中删除了 EntityFramework.dllEntityFramework.SqlServer.dll并从 CodePlex 获取它们的源代码并将它们添加到我的解决方案中。

我将这些新项目配置更改为 DebugNet40(因为我的项目使用 .NET 4,但使用 EntityFrameworkEntityFramework。 SqlServer 项目与 .NET 4.5 一起工作。

它编译成功,但是现在当我想运行我的项目时,出现以下错误:

An unhandled exception of type 'System.IO.FileLoadException' occurred in Microsoft.VisualStudio.HostingProcess.Utilities.dll

Additional information: Could not load file or assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. Strong name validation failed. (Exception from HRESULT: 0x8013141A)

这是我的app.config 文件:

<?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" />
  </configSections>
  <entityFramework>
     <defaultConnectionFactory 
          type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, 
                EntityFramework">
          <parameters>
             <parameter value="mssqllocaldb" />
          </parameters>
     </defaultConnectionFactory>
     <providers>
     <provider invariantName="System.Data.SqlClient" 
               type="System.Data.Entity.SqlServer.SqlProviderServices, 
               EntityFramework.SqlServer" />
     </providers>
  </entityFramework>
  <connectionStrings>
     <add name="ERPContext" 
                connectionString="Data Source=.;Initial Catalog=MyDb;
                Persist Security Info=True;User ID=sa;password=*****" 
                providerName="System.Data.SqlClient" />
  </connectionStrings>
</configuration>

我也从 app.config 中删除了 PublicKeyToken=b77a5c561934e089",但问题仍然存在。

有什么想法吗?

最佳答案

Entity Framework 源代码配置为生成延迟签名的程序集(这意味着它们被标记为“将来应该使用官方 key 签名”)。官方说明在Entity Framework's GitHub page演示如何禁用强名称验证(运行 EnableSkipStrongNames 任务:build/t:EnableSkipStrongNames),这样您就可以使用延迟签名的程序集,而无需任何人发布他们的私钥。这对于开发系统来说已经足够了。

如果您打算发布依赖于您自定义构建的修改后的 Entity Framework DLL 的产品,您应该生成一个新 key ,并修改 EF 源代码以使用该新 key 。

关于c# - 使用 EntityFramework 源项目而不是其程序集的解决方案无法成功启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26463561/

相关文章:

c# - 比较两个 utf-8 编码字符串的 byte[] 是否与比较两个 unicode 字符串相同?

c# - EF 5 一对多自引用 - 代码优先

spring - 如何从 java 代码配置 spring boot 服务器(初始化时)?

java - 我如何使用 log4j2 为不同的类使用不同的日志记录级别?

java - 用于在 Windows 中更改用户权限的批处理/bash/可执行文件

c# - 为什么我的 WPF 应用程序会在我碰撞鼠标滚轮时崩溃?

c# - 如何同时更新 32 位和 64 位 machine.config

c# - 垃圾收集如何决定变量的生成

c# - 如何在 Entity Framework 核心 rc2 中实现类型安全枚举模式

c# - Entity Framework 在运行时更改连接