Problems with Assembly Trust

8 April 2010 · 2 minute read · .net · trust-level · autofac · fail

When I was migrating PaulPad to ASP.NET MVC2 I decided that I wanted to also upgrade it to Autofac2. The main reason for it was the type registration is much nicer with it’s lambda syntax than it was in the 1.4 release which PaulPad previously used.

So I set about downloading the latest version of Autofac and getting it up and running.

Because Autofac2 supports both MVC1 and MVC2 I needed to use Assembly Binding to ensure that it worked properly. And this is where everything started to go bad. I kept getting weird a weird runtime error, an EntryPointNotFoundException was being thrown.

At the time I couldn’t get Autofac2 to compile for .NET 3.5 (I’ve since produced a patch to fix that) so I was in a world of pain.

I did manage to get it working by implementing my own controller registration and my own IControllerFactory and then it was working fine, even though I used the source of the AutofacControllerFactory! By now I was scratching my head massively, I mean, I’m doing exactly what they are doing, but why does mine not work?

From the limited debugging I was able to do (kind of hard when you don’t have the Autofac PDB’s) I found out that when calling builder.RegisterControllers nothing was happening. The controllers weren’t being found. Huh? But they were in the assembly, so it wasn’t making sense.

Once I got Autofac to compile though I did some debugging and was getting a weird error when it run the following code:

typeof(IController).IsAssignableFrom(controllerType);

The error was:

Type IController exists in System.Web.Mvc.dll and System.Web.Mvc.dll

(Well, something to that effect anyway)

So I was sitting there with a completely dumbfounded looked on my face, of course it exists in that assembly, by why does it look there twice? The only logical thought was that it wasn’t doing the assembly binding properly. But how can that be? I’ve not had assembly finding fail before, if it failed it shouldn’t have compiled.

Shit wasn’t making sense.

So I rolled back to my downloaded version of Autofac and decided to check the version number, but immediately upon opening up the properties dialog I say the message “This file came from another computer and might be blocked to help protect this computer”, and then there was the Unblock button.

facepalm

So I clicked Unblock, compiled and magic happened. It all worked, no problems what so ever.

Moral of this story

Trust everyone


Published: 2017-07-30 20:47:37 +1000 +1000, Version: bfd8bbd