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 instance. Perfect in combination with NHibernate, for example.
If you want to do this in the current .Net 4.0 beta you’re 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
Thanks for this Emil, it was very useful. System.Data.SQLite now happily working for me on 2010.
Thanks a lot, i did a migration for my project from sqlce to sqlite and encountered this problem. Your solution worked.
Trying to figure out how to get this to work with the resharper test runner
Me too 🙂
If you’re successful, please leave a note!
/Emil
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
Oh God! Thanks alot 🙂 you saved me!!!
A is a dll, B is also a dll, B will reference A.
C is a exe, C will reference B.
Debugging C, in B it alsways throws the same error at the place calling A as we talked.
So where should the configuration be put, in C, A, or B?
Well, as far as I know you can’t have configuration files for DLLs, unless you explicitly load them. So the answer is: C
If C is also dll, which is that Extensibility project for office, so how can I do it?
Actually, I don’t want to load the configuration.
Ok, so you have an Office extension that needs access to a Sqlite database? I think you might be in trouble in that case.
The correct place to insert the configuration in the post would be in the config file for Word/Excel/… but I don’t know if they even have config files. Even if they do, it feels very dirty to modify them.
However you could try to find another Sqlite version that perhap might work better for you. This post was written almost 1.5 years ago and there have been newer versions since then, e.g. with 64 bit support. If you’re lucky you won’t need the config hacks in this post.
Thank you very much.
I’m sorry I did not describe cleary of my trouble. Actually, I don’t use Sqlite.
All the dlls are developed by myself, any they are all upgrade from .net 2 to 4. The differences between them are that:
C is extensibility project for outlook2003, and B is a middle dll used by C, and B just use the A. A is a dll that created from xml schema file(.xsd, the xsd is against .net2, when I upgraded it, just changed the target framework to 4), sure, A has been generated by the .net 4 tools, like xsd.exe, csc.exe.
In B, there is a code like typeof(someclassname), the classname is difined in A, here, it always throw the error. I have tried adding configuration to each of them, but all failed.
Hope above info can give you an overview of my question.
Thanks again.
Actually, I’m pretty confused about exactly what problem you’re having. 🙂 Do you mean that you’re getting the “Mixed mode assembly” exception?
I’d say that your best bet would then be to make sure you generate/compile all your assemblies for .Net 2. I’m not sure if Office can work with .Net 4 components…
It works. Thanks!