Unity and MVC3

I recently moved my class based on IUnityResolver from the mvc3 project (where I tested it), to a class library (which references all five Unity dll’s. I’m getting the following error, why? Are there other dependencies for which I am unaware?

The type or namespace name ‘IUnityContainer’…are you missing an assembly or reference?

After toying with things a bit, I think I have a major system hosing in process. Forget the issue above. Check out the simple class below…

public class DomainContext : DbContext

public DomainContext() : base(“BuzzBoxConnectionString”) { }

protected override void OnModelCreating(ModelBuilder modelBuilder)
modelBuilder.Configurations.Add(new CategoryConfiguration());


This was working yesterday, but it isn’t being fired now. To be certain, I created a new mvc app, and added the entity class, the configuration class, and this one to the models folder, then simply instantiated it in the default controller. It steps through the ctor, but never fires the override.

What the heck? Is my registry hosed or something?

.NET really does not get near the registry except very low down. My bet is you’ve got a 3rd party reference issue, where you’ve got code in assembly A that calls code from assembly B which depends on assembly C. Under certain circumstances your build will not get all the dependencies of B (eg – Unity) so you get DLL not found errors.

Dumb hack to get around this is just directly call something from the assembly so references get resolved. Someone smarter than me can probably explain this a bit better and actually tell you why this is happening.

Well this was a wierd experience.

After almost an hour, the first issue self-resolved, though I have no clue why. I was just looking at the file when the squiggly lines under the class name just went away. This has happened before, just not quite so long.

The second issue was my bad. I had removed a single line of test code, removing the call that actually causes enumeration on the results of a query. Having not actually done anything, the context had no need for the model yet.