4

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?

John Kenedy
  • 41
  • 1
  • 2

3 Answers3

4

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.

Stephen Cleary
  • 437,863
  • 77
  • 675
  • 810
  • Nice info, I thought SQLite is pure managed code. Hopes this can solve my client issues. Will ask them to try it. – John Kenedy Dec 08 '10 at 03:25
1

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>
Berryl
  • 12,471
  • 22
  • 98
  • 182
0

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.

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
  • How do you know? Anyhow I edited to include the WinDBG stuff:) – Jeremy Thompson Dec 08 '10 at 02:38
  • The OP wrote: "How do I force the EXE to load the referenced DLL into CLR 4.0" - so I was thinking he was experiencing problems referencing the SQLLite DLL into his project and the Client Profile is a typical cause of that issue. Anyway, no harm no foul:) – Jeremy Thompson Dec 08 '10 at 03:04
  • Hi, I highly suspect it is the SQLite because before I use SQLite, it is running fine in my client computer which only installed .NET Framework 4.0. After I reference SQLite, the problems start happening. May I know what is the different between Client vs Full profiles and what impact it will have on the EXE? – John Kenedy Dec 08 '10 at 03:35
  • Rather than repeat a good answer here you go: http://stackoverflow.com/questions/2759228/difference-between-net4-client-profile-and-full-framework-download. John as Slaks asked, can you please copy and paste the exception into your question? Thanks. You know SQLLite references the Mono.Security.DLL and I read somewhere(afaik by Miguel de Icaza) that Mono components can run under .Net framework and vice versa. Not sure tho if this works for different versioned DLLs with the "supported Runtimes tag" as Stephen & I mentioned. Does the problem occur if you install .Net 2.0 on your clients system? – Jeremy Thompson Dec 08 '10 at 04:13