【发布时间】:2011-03-11 21:04:11
【问题描述】:
大约 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(字符串 [] 命令行) 在 SchoolManager.My.MyApplication.Main(String[] Args) 在 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81 在 System.AppDomain._nExecuteAssembly(RuntimeAssembly 程序集,字符串 [] 参数) 在 System.AppDomain.ExecuteAssembly(字符串 assemblyFile,证据 assemblySecurity,String [] args) 在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 在 System.Threading.ThreadHelper.ThreadStart_Context(对象状态) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback 回调,对象状态,布尔 ignoreSyncCtx) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback 回调,对象状态) 在 System.Threading.ThreadHelper.ThreadStart() 内部异常:System.IO.FileLoadException Message=混合模式程序集是针对版本“v2.0.50727”构建的 运行时,并且无法在 4.0 运行时中加载而无需额外的 配置信息。 来源=Dinofage.Data.XpressData 堆栈跟踪: 在 Dinofage.Data.XpressData.ExecuteSelectInternal(字符串选择命令) 在 Dinofage.Data.XpressData.ExecuteSelect(字符串选择命令) 在 D:\Alex\Documents\Visual Studio 2008\Projects\School Manager\SchoolManager\Modules\Academics.vb 中的 SchoolManager.Academics.GetNewAdmissionCode(String AcademicYear):第 89 行 在 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() 内部异常:
可能出了什么问题,我该如何解决?
【问题讨论】:
-
我为 .NET 4.0 重新编译了类库,但仍然无法正常工作。难道是因为我在类库中引用了SQLite.NET 1.0.65.0?
-
重要提示:如果错误发生在错误列“文件”为
SGEN,则修复需要位于sgen.exe.config旁边的文件sgen.exe中。例如,对于 VS 2015,创建C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6 Tools\sgen.exe.config。来源:SGEN Mixed mode assembly 最小文件内容:<configuration><startup useLegacyV2RuntimeActivationPolicy="true"/></configuration>
标签: .net .net-4.0 mixed-mode