Mixed Assembly Mode Error with .NET 4.0, SQLite, NUnit, and PartCover

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.

About Ashiq Alibhai, PMP

Ashiq has been coding C# since 2005. A desktop, web, and RIA application developer, he's touched ASP.NET MVC, ActiveRecord, Silverlight, NUnit, and all kinds of exciting .NET technologies. He started C# City in order to accelerate his .NET learning.
This entry was posted in Tools, Wndows Forms and tagged , , , . Bookmark the permalink.

One Response to Mixed Assembly Mode Error with .NET 4.0, SQLite, NUnit, and PartCover

  1. badmash says:

    I just signed up to your blogs rss feed. Will you post more on this subject?

Leave a Reply

Your email address will not be published. Required fields are marked *