我有一个UI&我遇到问题的解决方案的图书馆项目。图书馆项目使用Entity Framework&单元测试工作正常。该项目是一个C#4.0 WPF应用程序。
为了尝试获得基本的EF代码行,我将连接字符串从Library项目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="C:\Documents and Settings\Owner\My Documents\My Dropbox\source\MyInternetUsage\MyInternetUsageLibrary\MyInternetUsage.sqlite"'" providerName="System.Data.EntityClient" />
</connectionStrings>
答案 0 :(得分:3)
将以下指令添加到app.config
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
这应解决您的混合模式问题。