<p>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.</p>

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

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

<blockquote>
  <p>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 (...)'</p>
</blockquote>

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

<p>Now, here's the thing:</p>

<ol>
<li>All uses of <code>SuperException</code> have been eliminated from the project's code.</li>
<li>Compared to another project that compiles fine without a reference to <code>SuperException.DLL</code>, I only reference one more assembly - and <code>that</code> references nothing that my project doesn't reference itself. While it's possible that any of these dependencies could throw <code>SuperExceptions</code>, I'm only catching the base Exception class and in any case... the other project builds fine!</li>
<li>I've done Visual Studio's "Clean Solution" and cleared everything out by hand, many times.</li>
</ol>

<p>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!</p>

[{'answer_id': 9186, 'author': 'Iain Holder', 'author_id': 1122, 'author_profile': 'https://Stackoverflow.com/users/1122', 'pm_score': 0, 'selected': False, 'text': "<p>This sounds pretty strange.  Here's what I would check next:</p>\n\n<ol>\n<li>Check that there's nothing lingering in your Properties/AssemblyInfo.cs file.</li>\n<li>Check that there's nothing lingering in your SuperUI.csproj file.</li>\n<li>Delete all references and re-add them.</li>\n</ol>\n"}, {'answer_id': 9189, 'author': 'Joseph Daigle', 'author_id': 507, 'author_profile': 'https://Stackoverflow.com/users/507', 'pm_score': 1, 'selected': False, 'text': "<p>Since it's a compiler error, there must be a reference or use of SuperException somewhere in the project.</p>\n\n<ol>\n<li>Do a find/replace in the entire project or solution for that type and remove every reference (it's possible you already did this).</li>\n<li>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.</li>\n</ol>\n\n<p>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.</p>\n"}, {'answer_id': 9194, 'author': 'Lance Fisher', 'author_id': 571, 'author_profile': 'https://Stackoverflow.com/users/571', 'pm_score': 0, 'selected': False, 'text': '<p>Try creating a new project, and adding all your classes to it.</p>\n'}, {'answer_id': 9196, 'author': 'Michael Stum', 'author_id': 91, 'author_profile': 'https://Stackoverflow.com/users/91', 'pm_score': 2, 'selected': False, 'text': '<ol>\n<li>Exit Visual Studio</li>\n<li>Delete the bin and obj Folders in your solution directory</li>\n<li>Restart and see what happens</li>\n</ol>\n'}, {'answer_id': 9206, 'author': 'Stu', 'author_id': 414, 'author_profile': 'https://Stackoverflow.com/users/414', 'pm_score': 0, 'selected': False, 'text': '<p>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.</p>\n'}, {'answer_id': 9220, 'author': 'Dogmang', 'author_id': 1135, 'author_profile': 'https://Stackoverflow.com/users/1135', 'pm_score': 1, 'selected': False, 'text': "<p>Thanks for your answers so far. I've tried every suggestion (except one) to no avail.</p>\n\n<p>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.</p>\n"}, {'answer_id': 9226, 'author': 'Will Dean', 'author_id': 987, 'author_profile': 'https://Stackoverflow.com/users/987', 'pm_score': 1, 'selected': False, 'text': "<p>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.</p>\n\n<p>Have you really grep'd or findstr'd the whole solution tree, <em>every single file</em>, for a reference to that exception?</p>\n"}, {'answer_id': 9270, 'author': 'Rob Cooper', 'author_id': 832, 'author_profile': 'https://Stackoverflow.com/users/832', 'pm_score': 2, 'selected': False, 'text': "<p>I agree with the other comments here.. There is a reference, in plain text <em>somewhere</em> !\nI 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.</p>\n<p>I don't think that creating a new project is the solution here.. You need to be positive that <strong>NONE</strong> of the references in your dependency tree use SuperException.. <em>NONE</em></p>\n<p>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 <strong>every</strong> file.</p>\n<h3>EDIT:</h3>\n<p>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 :)</p>\n"}, {'answer_id': 9276, 'author': 'Orion Edwards', 'author_id': 234, 'author_profile': 'https://Stackoverflow.com/users/234', 'pm_score': 0, 'selected': False, 'text': '<blockquote>\n  <p>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.</p>\n</blockquote>\n\n<p>Seconded on that.</p>\n\n<p>You might not be referencing <code>SuperException</code>, but you might be referencing <code>SpecializedSuperException</code>, which is derived from, or somehow otherwise uses <code>SuperException</code> - your grep of the project for <code>SuperException</code> won\'t be catching it though.</p>\n\n<p>Try have a hack with the trial of <a href="http://www.ndepend.com/NDependDownload.aspx" rel="nofollow noreferrer">NDepend</a></p>\n'}, {'answer_id': 9350, 'author': 'Bernard', 'author_id': 61, 'author_profile': 'https://Stackoverflow.com/users/61', 'pm_score': -1, 'selected': False, 'text': '<p><code>grep -R SuperException *</code> in the base of your project (get <code>grep</code> from somewhere first) just to be sure.</p>\n'}, {'answer_id': 9375, 'author': 'Jon Limjap', 'author_id': 372, 'author_profile': 'https://Stackoverflow.com/users/372', 'pm_score': 0, 'selected': False, 'text': '<p>This is where tools like <a href="http://www.jetbrains.com/resharper/" rel="nofollow noreferrer">Resharper</a> really pay off -- a simple Find Usages usually tells me of such "ghost dependencies" several times.</p>\n\n<p>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 <em>circular dependency</em> on your main assembly (e.g., main assembly depends on exception assembly depends on main assembly...).</p>\n'}, {'answer_id': 20023, 'author': 'Shaun Austin', 'author_id': 1120, 'author_profile': 'https://Stackoverflow.com/users/1120', 'pm_score': 2, 'selected': False, 'text': "<p>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.</p>\n\n<p>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.</p>\n"}, {'answer_id': 559613, 'author': 'Henrik', 'author_id': 63621, 'author_profile': 'https://Stackoverflow.com/users/63621', 'pm_score': 3, 'selected': True, 'text': '<p>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. </p>\n\n<p>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.</p>\n\n<p>This most often happends to me when I reference Castle.Windsor but not Castle.MicroKernel. :p</p>\n'}, {'answer_id': 5760084, 'author': 'dmihailescu', 'author_id': 376495, 'author_profile': 'https://Stackoverflow.com/users/376495', 'pm_score': 0, 'selected': False, 'text': '<p>I’ve had a very similar assembly reference issue that was happening when my C# library had a dependent C++/CLI assembly. \nThe problem that was I was inheriting a public class from that C++/CLI assembly in my C# assembly library. That meant that the inheritance chain was spanning across multiple assemblies.</p>\n\n<p>I was hoping that any client would be smart enough to indirectly load the C++/CLI assembly any time the C# library needed it, but that was not the case even at compile time.</p>\n\n<p>I got rid of this problem by breaking the inheritance between the classes that were spanning across those two assembly libraries and using aggregation instead.\nMy client was finally happy and did not require the C++/CLI assembly as a dependency anymore.</p>\n\n<p>In your word you would probably have to make sure that <code>SuitableStandardException</code> does not inherit from <code>SuperException</code> in order to eliminate the <code>SuperException.DLL</code> as a reference.</p>\n\n<p>Use encapsulation instead of inheritance and create a <code>SuperException</code> data member in your new  <code>SuitableStandardException</code>.</p>\n\n<p>If that does not solve it, you might have more classes spanning inheritance across some assemblies, in your case <code>SuperAssembly.DLL</code> and <code>superException.dll</code>.</p>\n\n<p>If you can\'t find all of them try this trick:</p>\n\n<ol>\n<li><p>Make all your public members and classes in <code>SuperAssembly.DLL</code> internal.</p></li>\n<li><p>In the SuperAssembly.DLL make friends with <code>SuperException.DLL</code>:</p>\n\n<pre><code>[assembly:InternalsVisibleTo("SuperException, PublicKey=0024000004800000....)]\n</code></pre></li>\n<li><p>Make sure that they build and remove the <code>SuperAssembly.DLL</code> reference from any client that already references <code>SuperException.DLL</code>.</p></li>\n</ol>\n'}]
['https://Stackoverflow.com/questions/9173', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1135/']