Emil’s Blog

Programming Windows, .Net, EPiServer and whatnot…

[Powered by WordPress.]

November 20, 2009

NUnit with SQLite and .Net 4.0 Beta 2

by @ 12:05. Filed under .Net programming, NHibernate, Tools

SQLite and unit testing is a great combination for testing database operations without having to manage database files. You can simply create an in-memory database in your setup code and work with that. Perfect in combination with NHibernate for example.

If you want to do this in the current .Net 4.0 beta your out of luck though, you'll get an 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.

The solution is pointed out by Jomo Fisher. What you do is to include this snippet in the application config file:

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

When unit testing assemblies that references System.Data.SQLite.DLL then you have to put that snippet in NUnit's config file (C:\Program Files\NUnit 2.5.2\bin\net-2.0\nunit.exe.config).

If you combine this with the tip in my post NUnit with Visual Studio 2010 Beta 2, you should insert the following

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

plus

<loadFromRemoteSources enabled="true" />

under the runtime tag.

This works for me, hopefully it will for you as well.

/Emil

5 Responses to “NUnit with SQLite and .Net 4.0 Beta 2”


  1. Robert Boyd Says:

    Thanks for this Emil, it was very useful. System.Data.SQLite now happily working for me on 2010.


  2. claud Says:

    Thanks a lot, i did a migration for my project from sqlce to sqlite and encountered this problem. Your solution worked.


  3. John Says:

    Trying to figure out how to get this to work with the resharper test runner


  4. Emil Åström Says:

    Me too :-)

    If you're successful, please leave a note!

    /Emil


  5. mspspeak Says:

    Thanks! I had the startup in my project config alongside my nunit file but didn't think that the nunit.exe.config would need it.

    Awesome!
    @mspspeak

Leave a Reply

[powered by WordPress.]

jour·nal n. A personal record of occurrences, experiences, and reflections kept on a regular basis; a diary.

Internal links:

Categories:

Search blog:

Archives:

September 2010
M T W T F S S
« Jun    
 12345
6789101112
13141516171819
20212223242526
27282930  


View Emil Åström's profile on LinkedIn

General links:

I read:

Visitors

Recent Comments

Spam caught

Other:

Clicky Web Analytics

41 queries. 0.547 seconds