Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have written a simple interface and placed it in its own assembly. It defines one method (see attached). In another assembly, I have added a reference to the interface assembly, and I have a using statement at the top of the class. I specify the class is supposed to implment the interface.

 

And indeed, if I do not implement the method, I get a compilier error about the missing method. But I also get the following compilier error:

 

C:\cosp_ui_solution\cosp_ui\WindowsApplication1\bin\Debug\COSPDialogs.dll Referenced class 'COSPDialogs.BaseDialog' has base class or interface 'COSPInterfaces.EnableNotify' defined in an assembly that is not referenced. You must add a reference to assembly 'COSPInterfaces'.

 

I have tripled checked that I am referencing the assembly that defines the interface. And for kicks, I added another class to the interface assembly, and I make an instance of that class in my class that is implementing the interface. I dont get any problems with this, so I know that it is finding the reference to that assembly.

 

The only other clue if that I got the above error message twice when I first started, and the only way I could get rid of one of the messages was to add a reference to the interface into the assembly of the main application (a third assembly).

 

I tried defining the interface in its own class file in the same assembly as the implementor, and this worked fine. So there must be some trick to declaring an interface in one assembly, and referencing that interface from another assembly.

 

I also tried using explicit naming for the interface. That is, I used the fully qualified package, class and method name where I defined my implemented method, but I still got the same error.

 

All of this seems totally broken. I simply want to build an interface and implement it. But with this error, I am unable to do anything.

 

Can someone suggest how I can resolve this problem or at least understand what is wrong? Where could the problem be?

 

thanks

Bryan

 

 

Here is the top of the class that is implementing the interface:

 

using COSPInterfaces;

 

namespace COSPDialogs

{

public class BaseDialog : System.Windows.Forms.Form, COSPInterfaces.EnableNotify, ICloneable

 

public void setEnable( bool value )

{

this.m_isEnabled = value;

this.Invalidate( );

}

}

enablenotify.cs

  • *Gurus*
Posted

It means that in the assembly that contains your interface(s), you are referencing an assembly that you are not referencing in the project you are referencing the interfaces in.

 

That's a bit wordy, but if you have a type from an assembly referenced by a member of the interface, your project with the class that implements that interface must reference that assembly too.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

The assembly that holds my interface has references to System, System.Data and System.XML, and all of these are referenced in the assembly that uses the interface, as well as the assembly of my main application. I remove them since I do not need them. Then I tried something I did not try before, and it fixed the problem.

 

 

In the line where I declare my class, I orginally had

 

COSPInterfaces.EnableNotify

 

But if I simply put EnableNoitfy without the package name, it worked. So I have a using clause for the package, and I do NOT use the package name when I declare my class.

 

I remember reading about two different ways you can implement interfaces, one with a package name, and one without. Can you tell me anything about this difference or perhaps explain why what I did seems to make the difference?

 

thanks

Bryan

  • *Gurus*
Posted

I really don't know, I'm afraid. I've only ever got that error when it actually makes sense, i.e. I'm referencing a type in one assembly that I need to reference in another. I've used interfaces a great deal, but I guess I've just done what you did, specifying the full name inside the interface.

 

You might try posting on the MS C# newsgroup and see if they have a better way of explaining it.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

  • 10 months later...
Posted

I think the issue is an ambigious message

 

I had the same issue, and found your message.

 

The way I solved it was I created 3 classes:

 

<<< >>>>

using System;

 

namespace ClassLibrary1

{

public class CustomSuperClass

{

public void SuperClassMethod()

{

return;

}

public CustomSuperClass()

{

}

}

}

 

<<<>>>

<< next class >>

using System;

using ClassLibrary1;

 

namespace ClassLibrary2

{

public class CustomSubClass : ClassLibrary1.CustomSuperClass

{

public CustomSubClass()

{

}

}

}

 

<<>>>>

<third class>>

I called it TestInheritance

is just a windows form

it "uses" using ClassLibrary2; and i have a button with this:

 

private void button1_Click(object sender, System.EventArgs e)

{

 

CustomSubClass cs = new CustomSubClass();

cs.SuperClassMethod();

 

}

 

<<<>>>

 

why did I do all this? because the message from .NET points you to the wrong thing.

 

 

 

c:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\TestInheritance\bin\Debug\ClassLibrary2.dll Referenced class 'ClassLibrary2.CustomSubClass' has base class or interface 'ClassLibrary1.CustomSuperClass' defined in an assembly that is not referenced. You must add a reference to assembly 'ClassLibrary1'.

 

What fixes this is:

Adding ClassLibrary1 to TestInheritance

 

Notice in the message that there is NO reference to TestInheritance

 

The error message would be better suited if it read:

 

You must add a reference ( pointing to )'ClassLibrary1' IN the Project/Class called TestInheritance.

 

 

Maybe that will help someone in the future. I lost a day on this crap. cuz the message NEVER said anything about the class that actually needed the reference.

 

..

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...