We talked in a previous post about mixing SQLite (either via SQLite.NET or DevArt dotConnect For SQLite) with .NET 4.0. You will probably see this error:
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.
To reiterate, this error occurs because the way in which .NET loads assemblies changed between 4.0 and 2.0; therefore, this becomes an incompatible load. You can resolve this by telling .NET to use the legacy loading style with older assemblies (you’d think they’d make this the default) by adding two blocks to your App.Config or Web.Config file.
First, in the
startup tag (or add one if it doesn’t exist):
Second, in the
runtime tag (or add one if it doesn’t exist):
This configuration allows your application to load the 2.0 assemblies without error.
Great! But now, you’ll notice the exact same error appears when you run NUnit, and all your tests fail. Why?
Well, if you think about what we did, we added configuration so that our application can load the old assemblies. NUnit is also a .NET 4.0 application, and it also needs to know that it should load 2.0 assemblies the legacy way.
But we don’t have access to App.Config for NUnit! But wait! If you look in the NUnit folder, you’ll see NUnit.exe, and also NUnit.exe.config. This is essentially the App.Config file for NUnit. So open it up and make the same changes, and viola–NUnit now runs (and hopefully passes) the tests without error.
Unfortunately, the same error also occurs with PartCover — all of our tests fail with the same assembly loading. And modifying the PartCover.exe.config file doesn’t seem to make a difference. What’s going on?
Recall that PartCover uses NUnit to run the tests. This means that the actual application running our assembly is not PartCover, but is NUnit — whatever NUnit exe you specified in your config (most likely NUnit-agent.exe).
So the solution is to update the NUnit-agent.exe.config file, and viola–everything works!
Cheers to Emil from Emil’s Blog who gave us a solution for the NUnit part of the problem.