【问题标题】:Entity Framework issue - "Mixed mode assembly...cannot be loaded in the 4.0 runtime without additional configuration information"实体框架问题 - “混合模式程序集......无法在 4.0 运行时加载,无需额外配置信息”
【发布时间】:2010-09-25 20:10:01
【问题描述】:

我有一个 UI 和库项目,用于解决我遇到问题的解决方案。该库项目使用实体框架,并且单元测试可以正常工作。该项目是一个 C# 4.0 WPF 应用程序。

为了尝试让基本的 EF 代码行正常工作,我将连接字符串从库项目 app.config 复制到 UI 项目 app.config。

当我使用简单的 EF 测试几行(见下文)运行项目时,我收到以下错误。请注意,这两个项目都已设置为使用 .NET Framework 4。我确实使用了其他库,例如 Quartz.Net,但是在包含以下行之前一切正常。

关于如何纠正此问题的任何建议?

    // Test ONly
    using (var dbContext = new Model1Container())
    {
        Debug.WriteLine("Total Usages = " + dbContext.Usages.Count());
    }

错误:

“混合模式程序集是针对运行时版本‘v2.0.50727’构建的,如果没有额外的配置信息,则无法在 4.0 运行时中加载。”

我复制到 UI 项目 app.config 中的连接字符串

  <connectionStrings>
    <add name="Model1Container" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SQLite;provider connection string='data source=&quot;C:\Documents and Settings\Owner\My Documents\My Dropbox\source\MyInternetUsage\MyInternetUsageLibrary\MyInternetUsage.sqlite&quot;'" providerName="System.Data.EntityClient" />
  </connectionStrings>

【问题讨论】:

    标签: c# .net wpf entity-framework entity-framework-4


    【解决方案1】:

    将以下指令添加到您的 app.config

    <startup useLegacyV2RuntimeActivationPolicy="true">
      <supportedRuntime version="v4.0"/>
    </startup>
    

    这应该可以解决您的混合模式问题。

    【讨论】:

    • 感谢得到它(最初确实把它放在错误的 app.config 中,doh) - 当需要这种混合模式兼容性时,框架不能自行工作
    猜你喜欢
    • 2015-06-09
    • 2012-02-26
    • 2011-03-30
    • 1970-01-01
    • 2012-04-04
    • 2012-08-11
    • 2012-08-03
    • 2013-01-08
    • 1970-01-01
    相关资源
    最近更新 更多