简体   繁体   中英

.NET Framework 4.0 with assemblies using 2.0

I have a Windows Form project built in .NET 4.0. And it refers to a DLL System.Data.SQLite which is built in .NET 2.0. When my exe file is deployed to my client who only install .NET Framework 4.0 in his machine (Windows XP), the exe crashes.

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?

Set useLegacyV2RuntimeActivationPolicy to true in your app.config ( more info ).

I have more info regarding SQLite on .NET 4 (particularly with EF4) on my blog .

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). 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.

2) match your build target platform to the dll that suits your needs first. Either 64x or 86x will work, but AnyCpu gets some sort of manifest exception. I reluctantly use x86 because it is safer and doesn't noticeably impact anything I am doing with it.

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). Do not expect to do much with any WPF views through Visual Studio either, as the XAML designer just will not be happy. It's fast and sweet once you get it going but the latest release isn't a no brainer.

HTH,
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

Right Click on Project > Proeprties > Compile tab > Advanced Compile Options > Target Framework. Make sure it isn't set to .Net Client > set it to just .Net 4 (Full)

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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