.net - .NET 4 中的混合模式程序集

标签 .net .net-4.0 mixed-mode

大约 2 年前,我在 .NET 2.0 中编写了一个用于数据库访问的类库,并且一直在 .NET 2.0、3.0 和 3.5 上使用它。

在我正在处理的当前项目(这是一个 .NET 4.0 应用程序)中,尝试使用旧的忠实类库,但出现以下异常:

System.InvalidOperationException 未处理
Message=创建表单时出错。有关详细信息,请参阅 Exception.InnerException。
错误是:混合模式程序集是针对运行时的“v2.0.50727”版本构建的
并且不能在没有附加配置信息的情况下在 4.0 运行时加载。
来源=学校经理
堆栈跟踪:
在 SchoolManager.My.MyProject.MyForms.Create__Instance__[T](T Instance) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 190
在 SchoolManager.My.MyProject.MyForms.get_frmGeneric()
在 D:\Alex\Documents\Visual Studio 2008\Projects\School Manager\SchoolManager\My Project\Application.Designer.vb:line 35 中的 SchoolManager.My.MyApplication.OnCreateMainForm()
在 Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
在 Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
在 Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
在 SchoolManager.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
在 System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ThreadHelper.ThreadStart_Context(对象状态)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
内部异常:System.IO.FileLoadException
消息=混合模式程序集是针对版本“v2.0.50727”构建的
运行时并且不能在没有额外的情况下在 4.0 运行时中加载
配置信息。
来源=Dinofage.Data.XpressData
堆栈跟踪:
在 Dinofage.Data.XpressData.ExecuteSelectInternal(String selectCommand)
在 Dinofage.Data.XpressData.ExecuteSelect(String selectCommand)
在 D:\Alex\Documents\Visual Studio 2008\Projects\School Manager\SchoolManager\Modules\Academics.vb:line 89 中的 SchoolManager.Academics.GetNewAdmissionCode(String AcademicYear)
在 D:\Alex\Documents\Visual Studio 2008\Projects\School Manager\SchoolManager\UserControls\StudentDetail.vb:line 20 中的 SchoolManager.StudentDetail..ctor()
在 D:\Alex\Documents\Visual Studio 2008\Projects\School Manager\SchoolManager\frmGeneric.Designer.vb:line 25 中的 SchoolManager.frmGeneric.InitializeComponent()
在 SchoolManager.frmGeneric..ctor()
内部异常:


可能有什么问题,我该如何解决?

最佳答案

最好的方法可能是在 Visual Studio 2010 中为 .NET 4.0 重新编译您的类库(即打开项目、转换它并更改目标框架。)

如果您不能或不会这样做,那么您可以尝试将以下内容添加到您的 .NET 4.0 应用程序的 app.config 文件中:

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

IE。
<?xml version ="1.0"?> 
<configuration> 
    <startup useLegacyV2RuntimeActivationPolicy="true">
        <supportedRuntime version="v4.0"/>
    </startup>
</configuration>

关于.net - .NET 4 中的混合模式程序集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3179028/

相关文章:

.net-4.0 - 轻量级代码生成(LCG)死了吗?

wpf - 从选项卡内部将选项卡添加到选项卡控件

c++ - Visual Studio:std::string 的乱码调试监视?

c++ - 在 mida 保护下的 Dllmain 死锁

c# - 混合模式程序集是针对 'v2.0.50727' 错误构建的

c# - 异步快速路径

c# - .Net 中非常大的集合导致内存不足异常

c# - 如何根据键值对创建对象

c# - 如何在 Outlook 2013 中禁用特定存储的索引?

c# - 如何验证 C# 代码?