简体   繁体   English

带有使用2.0的程序集的.NET Framework 4.0

[英].NET Framework 4.0 with assemblies using 2.0

I have a Windows Form project built in .NET 4.0. 我有一个在.NET 4.0中构建的Windows窗体项目。 And it refers to a DLL System.Data.SQLite which is built in .NET 2.0. 它指的是一个用.NET 2.0构建的DLL System.Data.SQLite。 When my exe file is deployed to my client who only install .NET Framework 4.0 in his machine (Windows XP), the exe crashes. 当我的exe文件部署到我的客户端,他只在他的机器(Windows XP)中安装.NET Framework 4.0时,exe崩溃了。

How do I force the EXE to load the referenced DLL into CLR 4.0 (although it is built to use CLR 2.0) so that without .NET Framework 2.0 installed, it still able to run? 如何强制EXE将引用的DLL加载到CLR 4.0中(虽然它是为了使用CLR 2.0而构建的),这样如果没有安装.NET Framework 2.0,它仍然可以运行?

Set useLegacyV2RuntimeActivationPolicy to true in your app.config ( more info ). 在app.config useLegacyV2RuntimeActivationPolicy设置为true更多信息 )。

I have more info regarding SQLite on .NET 4 (particularly with EF4) on my blog . 在博客上有关于.NET4上的SQLite(特别是EF4)的更多信息。

John 约翰

I have had issues with configuring SQLite too, which I use with NHibernate as opposed to EntityFramework (I think the last release might have considered EF more, not sure). 我也遇到过配置SQLite的问题,我使用NHibernate而不是EntityFramework(我认为最后一个版本可能更多地考虑了EF,不确定)。 Here is what currently works for me. 这是目前适合我的。

1) modify app.config as Stephen says, but also add a runtime directive for the reason in the comments below. 1)修改app.config作为斯蒂芬说,但也在下面的评论中添加运行时指令。

2) match your build target platform to the dll that suits your needs first. 2)首先将您的构建目标平台与满足您需求的dll相匹配。 Either 64x or 86x will work, but AnyCpu gets some sort of manifest exception. 64x或86x都可以工作,但AnyCpu会出现某种明显异常。 I reluctantly use x86 because it is safer and doesn't noticeably impact anything I am doing with it. 我不情愿地使用x86,因为它更安全,并没有明显影响我正在做的任何事情。

You might even find it useful at some point to make separate projects to isolate the dependency hassles in the latest release (I think it was April). 您甚至可能会发现在某些时候制作单独的项目来隔离最新版本中的依赖性麻烦(我认为是4月份)。 Do not expect to do much with any WPF views through Visual Studio either, as the XAML designer just will not be happy. 不要期望通过Visual Studio对任何WPF视图做很多事情,因为XAML设计师不会感到高兴。 It's fast and sweet once you get it going but the latest release isn't a no brainer. 一旦你开始它就会快速而甜蜜,但最新版本并非毫无疑问。

HTH, HTH,
Berryl Berryl

full app config additions 完整的应用程序配置添加

<!-- SQLite requires this mixed mode load setting-->
<startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>

<runtime>
    <loadFromRemoteSources enabled="true"/>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

    <!-- SQLite is built with older System.Data so we need this redirect -->       
    <dependentAssembly>
        <assemblyIdentity name="System.Data" publicKeyToken="b77a5c561934e089"/>
        <bindingRedirect oldVersion="2.0.0.0" newVersion="4.0.0.0"/>
    </dependentAssembly>

    </assemblyBinding>
</runtime>

Set .Net 4 to be Full Profile, see here msdn.microsoft.com/en-us/library/cc656912.aspx 将.Net 4设为完整档案,请点击此处msdn.microsoft.com/en-us/library/cc656912.aspx

Right Click on Project > Proeprties > Compile tab > Advanced Compile Options > Target Framework. 右键单击项目> Proeprties>编译选项卡>高级编译选项>目标框架。 Make sure it isn't set to .Net Client > set it to just .Net 4 (Full) 确保它未设置为.Net Client>将其设置为.Net 4(完整)

Edit: .NET Framework is backward compatible in general and you can setup supported Runtimes, see here http://social.msdn.microsoft.com/forums/en-US/clr/thread/de5956f6-7a12-45d8-ae03-988ad8434a17 编辑:.NET Framework一般是向后兼容的,您可以设置支持的运行时,请参见http://social.msdn.microsoft.com/forums/en-US/clr/thread/de5956f6-7a12-45d8-ae03-988ad8434a17

Regarding the crashing EXE, I'm guessing this is a second chance exception (ie one that the debugger cant handle) so you may want to take a memory dump and use WinDBG to !Analyze the memory dump and find out the exact cause, unless of course the second chance exception message lists the System.Data.SQLite as the problem DLL. 关于崩溃的EXE,我猜这是第二次机会异常(即调试器无法处理的异常),所以你可能想要一个内存转储并使用WinDBG来!分析内存转储并找出确切的原因,除非当然第二次机会异常消息列出System.Data.SQLite作为问题DLL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM