题
我在2年前在.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:
怎么了,我该如何解决?
解决方案
最好的方法可能是在2010年Visual Studio中为.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 4.0中新的程序中并排CLR版本支持,运行时不知道发生这种情况时需要提供哪个CLR版本。您必须告诉它,使用app.exe.config文件应该看起来像这样:
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
</configuration>
另一种方法:在VB 2010 Express中,您可以打开项目并转到“标签”编译,然后 Advanced Compile Options...
. 。选择 .NET Framework 2.0
从名称的下拉列表中 Target framework (all configurations)
.
如果您没有通过指定USELEGACYV2RUNTIMECTIVAIVACTYPOLICY =“ TRUE”来完成,则可能需要安装与OS和.NET版本兼容的设置。您可以在 http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki.
在安装此设置之前,请从已安装程序中卸载SQLite。这将在您的代码中显示错误。
如果即使在安装兼容设置后也无法正常工作,则必须删除对先前DLL文件的引用,并对此兼容的DLL文件添加新的引用。
当您添加对兼容DLL文件的引用时,您只需要构建项目,所有代码错误都应该消失。
您可以尝试在Visual Studio 2010内部打开旧的忠实项目(课堂库),并允许它为您进行转换。
如果其他人仍然遇到这个问题,这是我的诊断:您正在使用错误的SQLite软件包。有很多版本的sqlite http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki
例如,如果使用X86 Platorm定位.NET 4.5,则应使用此文件:
在32位窗户的预编译静态链接的二进制文件下(.NET Framework 4.5)
sqlite-netfx45静态二进制二进制 - 荷威32-2012-1.0.106.0.0.zip