Assembly binding redirects and pathological edge cases

by Matt 27. August 2009 19:07

I posted a little while ago that ReSharper had updated to 4.5.1, and that the test runner in xunitcontrib worked just fine with it, even though it was actually compiled against 4.5.

Except for one little edge case – all of the xunitcontrib tests themselves.

That was a little… perturbing.

ReSharperRunnerLoggerTests.ExceptionThrownCallsReportsExceptionAndFinishesClassTask : Failed

System.IO.FileLoadException: Could not load file or assembly
'JetBrains.ReSharper.TaskRunnerFramework, Version=4.5.1231.7, 
Culture=neutral, PublicKeyToken=1010a0d8d6380325' or one of its dependencies.
The located assembly's manifest definition does not match the assembly reference.
(Exception from HRESULT: 0x80131040) 

So what’s happening here?

The test runner plugin, compiled against ReSharper 4.5, is running (successfully) in the ReSharper 4.5.1 test runner. It is trying to execute its own test assembly, which is also compiled against ReSharper 4.5 (aka 4.5.1231.7). This test assembly is unable to find the ReSharper 4.5 assemblies, which are deployed into the same directory as the test assembly (I checked. Several times). And just to reiterate – the test runner plugin had no such assembly loading issues.

Surprisingly, this does make sense. It just took me a while to figure out.

Let’s start with the easy stuff. The test runner plugin is working due to plain old assembly redirects. ReSharper runs tests out of process, in an executable called JetBrains.ReSharper.TaskRunner.exe. If you look in its config file, you’ll see a ton of assembly redirects to map all ReSharper assemblies from and above to 4.5.1274.1 (ReSharper 4.5.1). So, when xunitcontrib is used to run some tests, the exe fires up, loads the plugin, redirects my dependencies to the newer versions and all is well.

(xunitcontrib also runs in the devenv.exe process. A quick look at the devenv.exe.config file sees another ton of redirects. I know it’s the correct way to do this, but it does feel a bit crufty stomping all of that into someone else’s config…)

That explains why the test runner works. Why don’t the tests?

Thanks to the very same redirects that make the test runner work.

Tests are run in the same JetBrains.ReSharper.TaskRunner.exe as the plugin, so the same redirects apply. The problem starts because the ReSharper test runner sets up some custom assembly resolving handling, meaning that when the CLR tries to find a ReSharper assembly, the test runner can point it to the ReSharper installation directory. But because the tests run in a new AppDomain, they don’t get this custom assembly lookup, and so can’t find the new assemblies. Annoyingly, it reports this as being unable to load the originally requested version of the assembly (the version which is in the same directory, causing lots of confusion).

There are two solutions to this.

Obvious: recompile to 4.5.1.

Simple: add an empty app.config file. When the new AppDomain is created, it uses this config file, so no more redirects and no more failing tests.

So, if you ever get stuck trying to dogfood a test runner to run its own tests in another AppDomain within the same process while redirecting assembly references - this post’s for you.

Tags: , , , ,

Comments (18) -

Carpentry Apprenticeships
Carpentry Apprenticeships
2/11/2011 12:49:30 PM #

The core of your writing whilst sounding reasonable initially, did not really work perfectly with me after some time. Somewhere within the paragraphs you actually were able to make me a believer unfortunately just for a short while. I nevertheless have got a problem with your leaps in assumptions and you might do nicely to help fill in those gaps. In the event you can accomplish that, I will certainly be amazed.


Carla Aderson
Carla Aderson
2/11/2011 5:43:39 PM #

Along with everything that seems to be building throughout this specific subject matter, many of your opinions are actually relatively refreshing. Nevertheless, I beg your pardon, because I do not give credence to your whole theory, all be it exciting none the less. It seems to everyone that your opinions are not entirely validated and in simple fact you are generally your self not fully certain of the argument. In any event I did take pleasure in looking at it.


buy overnight tramadol
buy overnight tramadol
3/7/2011 2:02:24 PM #

Its illegal distress hacks the exponential before the afternoon brush.


pacquiao vs mosley
pacquiao vs mosley
3/13/2011 2:35:39 AM #

your blog is very useful


playbook cases
playbook cases
4/10/2011 12:14:52 AM #

For an unbelievably complicated subject I think you explained it really well, you got the important points across and made them easy to understand


7/27/2011 10:48:32 AM #

Bienvenue sur fonctionnalités inédites, nombreuses annuaires.


Tim Smith
Tim Smith United States
9/8/2011 1:59:05 PM #

Really helpful many thanks, It looks like your trusty subscribers might possibly want a whole lot more reviews like that carry on the good effort.


philix United States
11/19/2015 6:29:49 PM #

good website


philix United States
11/20/2015 1:50:38 PM #

Good Site


Cornelius Styborski
Cornelius Styborski United States
1/15/2016 4:56:55 AM #

Printing out an essay or paper, reading the first line and realizing there aren't any mistakes.<br />AWESOME!


Lashawn Ulwelling
Lashawn Ulwelling United States
1/15/2016 4:58:47 AM #

getting laid AWSOME


Jinny Mccleese
Jinny Mccleese United States
1/15/2016 6:44:23 AM #

The dolphin saving you one is the best one!


Hannah Barbarino
Hannah Barbarino United States
1/15/2016 7:19:25 AM #

getting the last pair of shoes in your size AWESOME!


Terrell Sabel
Terrell Sabel United States
1/15/2016 7:49:04 AM #

Printing out an essay or paper, reading the first line and realizing there aren't any mistakes.<br />AWESOME!


Modesto Ziems
Modesto Ziems United States
1/15/2016 8:59:35 AM #

I love the dolphin saving you one.


Anna Farris
Anna Farris United States
7/20/2016 7:43:28 AM #

Take my word for it, it's not as easy as you think


Arlette Hodgin
Arlette Hodgin United States
8/25/2016 4:23:58 AM #

Construction industry is adapting the latest technology. Smart house buildersdesigners are having great niche


Hipolito M. Wiseman
Hipolito M. Wiseman United States
10/3/2016 5:22:23 AM #

Hands down, Apple's app store wins by a mile. It's a huge selection of all sorts of apps vs a rather sad selection of a handful for Zune. Microsoft has plans, especially in the realm of games, but I'm not sure I'd want to bet on the future if this aspect is important to you. The iPod is a much better choice in that case.


Add comment

  • Comment
  • Preview


Month List


Comment RSS