views:

1890

answers:

13

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=1.1.0.0 (...)'

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

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.

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!

A: 

This sounds pretty strange. Here's what I would check next:

  1. Check that there's nothing lingering in your Properties/AssemblyInfo.cs file.
  2. Check that there's nothing lingering in your SuperUI.csproj file.
  3. Delete all references and re-add them.
IainMH
+1  A: 

Since it's a compiler error, there must be a reference or use of SuperException somewhere in the project.

  1. Do a find/replace in the entire project or solution for that type and remove every reference (it's possible you already did this).
  2. If you reference any types that inherits from SuperException (even if the type defined in another assembly), you need a reference to the assembly that SuperException is defined in.

Take the line that the compiler is showing the error on and start tracing the inheritance tree of the objects used on that line, you might find the source of it that way.

Joseph Daigle
A: 

Try creating a new project, and adding all your classes to it.

Lance Fisher
+2  A: 
  1. Exit Visual Studio
  2. Delete the bin and obj Folders in your solution directory
  3. Restart and see what happens
Michael Stum
A: 

grep your project folder. It could be a hidden reference in your project, or a project that your project references. Cleanse with Notepad if needed.

Stu
+1  A: 

Thanks for your answers so far. I've tried every suggestion (except one) to no avail.

The suggestion I haven't tried is to create a new project and add all my stuff to it, the thought of which really tests my will to live. ;) I may try this tomorrow if I can be bothered. Thanks again.

Dogmang
+1  A: 

There is really nothing very mysterious about VS projects nowadays - it's all text files, etc. SOMETHING must reference that class/dll, and that something must be part of your project.

Have you really grep'd or findstr'd the whole solution tree, every single file, for a reference to that exception?

Will Dean
+1  A: 

I agree with the other comments here.. There is a reference, in plain text somewhere ! I have had similar problems in the past where searching through the project files returned nothing, turns out it was in some other file that wasn't automatically picked up in the search.

I don't think that creating a new project is the solution here.. You need to be positive that NONE of the references in your dependency tree use SuperException.. NONE

I have never experienced this to the point where I have needed to literally wipe the project, I have always found the reference somewhere. Ensure you are searching every file.

EDIT:

Just a point to add, if the location pointed to by the error seems random, that can often mean there is a mismatch between the compiled source and the source code file.. Is this a ASP.NET application? I have had it before where the compiled DLL's haven't been replaced on a rebuild in the ASP.NET temp folder causing things to get.. Interesting when debugging :)

Rob Cooper
A: 

If you reference any types that inherits from SuperException (even if the type defined in another assembly), you need a reference to the assembly that SuperException is defined in.

Seconded on that.

You might not be referencing SuperException, but you might be referencing SpecializedSuperException, which is derived from, or somehow otherwise uses SuperException - your grep of the project for SuperException won't be catching it though.

Try have a hack with the trial of NDepend

Orion Edwards
A: 

grep -R SuperException * in the base of your project (get grep from somewhere first) just to be sure.

Bernard
A: 

This is where tools like Resharper really pay off -- a simple Find Usages usually tells me of such "ghost dependencies" several times.

Maybe you could go to your definition of the SuperException class and try to Find All References(). You might also want to investigate if the assembly SuperException is has a circular dependency on your main assembly (e.g., main assembly depends on exception assembly depends on main assembly...).

Jon Limjap
+2  A: 

I don't think this is a code issue. What I can see happening is that one of your existing references probably rely on that type in their own types which you are probably creating in your application.

If that is the case you do need that reference even if you don't explicitly use the type and even though the other referenced assembly has its own reference. You sometimes get that issue with 3rd party components which need references to types that you haven't referenced. The compiler is obviously seeing something in one of your existing referenced assemblies and is expecting you to referenced the dependent one.

Shaun Austin
Try searching the other referenced assemblies for the SuperException with Reflector to verify that they aren't referencing the assembly.
CStick
+1  A: 

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.

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

Henrik