Problems with Assembly Trust

Thursday, Apr 8, 2010 2 minute read Tags: .net trust-level autofac fail
Hey, thanks for the interest in this post, but just letting you know that it is over 3 years old, so the content in here may not be accurate.

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