File not found exception


Have you ever seen a error like the one below:

System.IO.FileNotFoundException: Could not load file or assembly "Missing.Assembly.dll, Version=, Culture=neutral, PublicKeyToken=null" or one of its dependencies. The system cannot find the file specified.

The first thing to think is Ahhhhhhh! I have all the references what is going on??! Don't panic here's a few steps to diagnosing this issue, and hopefully resolving it.

  1. Make sure you can debug the code and ascertain which assembly is throwing the exception.
  2. Once you know which assembly is complaining about the missing DLL you then need to find the corresponding project and check that project's references:
Visual Studio solution explorer

If the reference exists then you need to look a little deeper, into the second part of the exception or one of its dependencies. This is key, what this means is that Missing.Assembly.dll is referencing an assembly you're not (FACT).

What you need to do is ascertain exactly which assembly it is referencing and which version it is referencing. This is actually quite tricky for large projects but the easiest way to find out is by looking at where the exception occured (i.e. the line of code) and what that particular piece of code needs to work in terms of references. Do this by looking at the using statements:

C# namespace declaration

Good luck ☺ Any questions?