Lingering assembly dependency in C# .NET

Question :

Lingering assembly dependency in C# .NET,

Answer :

My C# project – we’ll call it the SuperUI – used to make use of a class from an external assembly. Now it doesn’t, but the compiler won’t let me build the project without the assembly reference in place. Let me elaborate.

This project used to throw and catch a custom exception class – the SuperException – which was derived from the standard System.Exception and lived in a separate, precompiled assembly, SuperAssembly.DLL, which I referenced.

Eventually, I decided this was a pointless exercise and replaced all SuperExceptions with a System.SuitableStandardException in each case. I removed the reference to SuperException.DLL, but am now met with the following on trying to compile the project:

The type ‘SuperException’ is defined in an assembly that is not referenced. You must add a reference to assembly ‘SuperException, Version= (…)’

The source file referenced by the error doesn’t seem relevant; it’s the project namespace that gets highlighted in the IDE.

Read More  Watch for change in ip address status

Now, here’s the thing:

  1. All uses of SuperException have been eliminated from the project’s code.
  2. Compared to another project that compiles fine without a reference to SuperException.DLL, I only reference one more assembly – and that references nothing that my project doesn’t reference itself. While it’s possible that any of these dependencies could throw SuperExceptions, I’m only catching the base Exception class and in any case… the other project builds fine!
  3. I’ve done Visual Studio’s “Clean Solution” and cleared everything out by hand, many times.
Read More  How to obtain good concurrent read performance from disk

It’s not the end of the world to include this reference, I just don’t see why it’s necessary any more. Nrrrgg. Any pointers welcome!


It’s likely a transitive reference, where some type method call returns an instance of SuperException boxed (“downcast”) as e.g. Exception, but from inspecting the code in the transitively included code, i.e. code from your external method calls, the compiler knows that you need to be able to have information about that type at some point.

Resharper would tell you where it’s the case that you need to add a reference, and you could use Lütz Roeder’s aka RedGate’s Reflector to scan compiled IL for a reference to this type in two ways: 1) use the search-facility, 2) open each public type you’re using and for that one which requires the “ghost” assembly, it will ask you to specify its location.

Read More  Select all columns except one in MySQL?

This most often happends to me when I reference Castle.Windsor but not Castle.MicroKernel. :p

That’s the answer Lingering assembly dependency in C# .NET, Hope this helps those looking for an answer. Then we suggest to do a search for the next question and find the answer only on our site.

Disclaimer :

The answers provided above are only to be used to guide the learning process. The questions above are open-ended questions, meaning that many answers are not fixed as above. I hope this article can be useful, Thank you