Thursday, August 16, 2012

I Feel Like I'm Taking Crazy Pills: Ninject, SignalR, and Nuget

"Could not load file or assembly 'Ninject, Version=, Culture=neutral, PublicKeyToken=c7192dc5380945e7' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference."

After 3 hours of wrestling with this error I have solved the problem but don't understand the solution. Maybe it is so blindingly obvious that I am overlooking it. As you can see from the video link below, however, this one really confused me.

Clearly there was an outdated reference in one of the three projects that comprised my prototype ASP.NET MVC 3 solution that was using Ninject and SignalR. I checked, double-checked, triple-checked references manually as well as in NuGet and everything seemed in order.

I noticed that one of my projects had an 'orphaned' NuGet packages.config file. This file had entries for Ninject and Ninject.Extensions.Conventions, but the project didn't actually have references to these assemblies.
<?xml version="1.0" encoding="utf-8"?>
  <package id="Ninject" version="" targetFramework="net40" />
  <package id="Ninject.Extensions.Conventions" version="" targetFramework="net40" />
I like to keep my projects lean and clean so I decided to tidy up. Rather than manually deleting the orphaned file, I decided to use Nuget, thinking that this might be a more thorough approach. After NuGet was finished I tried running the solution again, though I had zero expectations that the problem was solved.

I almost fell out of my office chair when the app started up successfully.

"What in tarnation changed?" I wondered. (I didn't actually use the word 'tarnation', but hopefully you get a sense of my surprise and bewilderment.) the Pending Changes window!

I was surprised to see that something had changed with the web.config file. Running a diff on the file revealed why my application had suddenly started to behave:binding redirection.

So that's it for now. Ninject and SignalR both work in harmony. I normally don't like to let mysteries like this linger unsolved, but I've got more important things to do today. (Visual Studio 2012 and Windows 8 are both available today, don't you know?)

1 comment:

  1. I have the same problem, but without SignalR. I did file new project in Visual Studio 2012, web forms 4.5, updated all nuget packages, added Ninject.web. Ran the project and get 'Could not load file or assembly 'Ninject, Version='. In my bin is a ninject.dll that has a version of 1.