.NET 4 中的混合模式程序集 [英] Mixed mode assembly in .NET 4
问题描述
大约 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:AlexDocumentsVisual Studio 2008ProjectsSchool ManagerSchoolManagerMy ProjectApplication.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) 在 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:AlexDocumentsVisual Studio 2008ProjectsSchool ManagerSchoolManagerModulesAcademics.vb:line 89 中的 SchoolManager.Academics.GetNewAdmissionCode(String AcademicYear)在 D:AlexDocumentsVisual Studio 2008ProjectsSchool ManagerSchoolManagerUserControlsStudentDetail.vb:line 20 中的 SchoolManager.StudentDetail..ctor()在 D:AlexDocumentsVisual Studio 2008ProjectsSchool ManagerSchoolManagerfrmGeneric.Designer.vb:line 25 中的 SchoolManager.frmGeneric.InitializeComponent()在 SchoolManager.frmGeneric..ctor()内部异常:<小时>
可能出了什么问题,我该如何解决?
最好的方法可能是在 Visual Studio 2010 中为 .NET 4.0 重新编译您的类库(即打开项目、转换它并更改目标框架.)
如果您不能或不会这样做,那么您可以尝试将以下内容添加到您的 .NET 4.0 应用程序的 app.config 文件中:
<supportedRuntime version="v4.0"/></启动>
即.
I wrote a class library in .NET 2.0 for database access some 2 years ago and have been using it all along on .NET 2.0, 3.0 and 3.5.
In the current project I'm working on (which is a .NET 4.0 application), tried using the old faithful class library and I got the following exception:
System.InvalidOperationException was unhandled Message=An error occurred creating the form. See Exception.InnerException for details. The error is: Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information. Source=SchoolManager StackTrace: at SchoolManager.My.MyProject.MyForms.Create__Instance__[T](T Instance) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 190 at SchoolManager.My.MyProject.MyForms.get_frmGeneric() at SchoolManager.My.MyApplication.OnCreateMainForm() in D:AlexDocumentsVisual Studio 2008ProjectsSchool ManagerSchoolManagerMy ProjectApplication.Designer.vb:line 35 at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel() at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine) at SchoolManager.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException: System.IO.FileLoadException Message=Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information. Source=Dinofage.Data.XpressData StackTrace: at Dinofage.Data.XpressData.ExecuteSelectInternal(String selectCommand) at Dinofage.Data.XpressData.ExecuteSelect(String selectCommand) at SchoolManager.Academics.GetNewAdmissionCode(String academicYear) in D:AlexDocumentsVisual Studio 2008ProjectsSchool ManagerSchoolManagerModulesAcademics.vb:line 89 at SchoolManager.StudentDetail..ctor() in D:AlexDocumentsVisual Studio 2008ProjectsSchool ManagerSchoolManagerUserControlsStudentDetail.vb:line 20 at SchoolManager.frmGeneric.InitializeComponent() in D:AlexDocumentsVisual Studio 2008ProjectsSchool ManagerSchoolManagerfrmGeneric.Designer.vb:line 25 at SchoolManager.frmGeneric..ctor() InnerException:
What could be wrong and how do I fix it?
The best would probably be to recompile your class library for .NET 4.0 in Visual Studio 2010 (ie. opening up the project, converting it, and changing the target framework.)
If you can't, or won't, do that, then you can try adding the following to your app.config file for your .NET 4.0 application:
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
ie.
<?xml version ="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
</configuration>
这篇关于.NET 4 中的混合模式程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!