SQLite and Visual Studio 2010/.NET 4.0

by Shawn December 10, 2009 07:54

SQLite is one of those gems in the development community. When you need a small, lightweight, fast, and FREE embedded database there is nothing better out there.  To top it off, the guys at PhxSoftware have done an absolutely fantstic job of creating a complete ADO.NET 2.0 data provider for SQLite.  The only downside right now is that it has not been updated for .NET 4.0 and Visual Studio 2010.  That said for those of you chomping at the bit to work in the latest and greatest there is no need to fear as we have a work around to get you up runnng.

If you are gettting this exception:

System.IO.FileLoadException: 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.

There is a solution that was first pointed out by Jomo Fisher. All you need to do is to include this snippet in the application config file:

<startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0"/>
</startup> 

Now, that said if you really want a native version it is possible as apparently recompiling the project and targeting .NET 4 works

  1. In order to compile sqlite.net with vs2010 beta 2 you can convert the 2008 solution. Before you convert the project files, you will need to remove the compact framework targets or the conversion will fail telling you that the compact framework is not supported.
  2. After the projects are converted set the targeted framework to .net 4

I could not get the netmodule to compile in vs2010 (it complained that the OutputType was not supported) but the netmodule will build when build from the command line with msbuild. The rest of the projects compile fine.

To get the designer to compile you will need to add a file called source.extension.vsixmanifest.The next thing I encountered was a System.TypeLoadException (Inheritance security rules violated by type). This could be solved by adding the following line to System.Data.SQLite/AssemblyInfo.cs

[assembly: SecurityRules(System.Security.SecurityRuleSet.Level1)]

There are some more minor changes to the project files to get it to compile but in the end it compiles with .NET 4 support and works without workarounds when used from .NET 4.

Tags: ,

Development

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen | Modified by Mooglegiant