大约两年前,我在 .NET 2.0 中编写了一个用于数据库访问的类库,并且一直在 .NET 2.0、3.0 和 3.5 上使用它。
在我正在处理的当前项目(这是一个 .NET 4.0 应用程序)中,尝试使用旧的忠实类库,但出现以下异常:
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:\Alex\Documents\Visual Studio 2008\Projects\School Manager\SchoolManager\My Project\Application.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:\Alex\Documents\Visual Studio 2008\Projects\School Manager\SchoolManager\Modules\Academics.vb:line 89
at SchoolManager.StudentDetail..ctor() in D:\Alex\Documents\Visual Studio 2008\Projects\School Manager\SchoolManager\UserControls\StudentDetail.vb:line 20
at SchoolManager.frmGeneric.InitializeComponent() in D:\Alex\Documents\Visual Studio 2008\Projects\School Manager\SchoolManager\frmGeneric.Designer.vb:line 25
at SchoolManager.frmGeneric..ctor()
InnerException:
可能出了什么问题以及如何修复它?
最好的方法可能是在 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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)