C# class not implementing VB.NET interface

G

Guest

OK...I must be missing something...can someone tell me what I'm not doing properly...

First, create an assembly with a single interface in VB.NET as follow

Public Interface IDo
Function Bark(ByVal lVolume As Long) As Strin
End Interfac

Pretty simple..

Now...in a second (C#) assembly...create a class that implements that interface...like so..

using System
using DogInterface

namespace CSImplemete

/// <summary
/// Summary description for Class1
/// </summary
public class Husky : IDo

public string Bark(long lVolume

return "Deep Bark!! at " + lVolume.ToString() + " level"




This is also pretty simple (as you can see...the namespace for the IDog is DogInterface...that is also the name of it's assembly). This all compiles very well...I have a single solution with both projects in it

Now...I create a new assembly...a VB.NET windows application in the same solution that will use that Husky Class. I have referenced the two assemblies from above and placed a single button on the form

In a click event for the test button, I have the following code

Imports CSImplemete
Imports DogInterfac

Public Class Form
Inherits System.Windows.Forms.For

[" Windows Form Designer generated code "

Private Sub cmdBark_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBark.Clic

Dim objDog As CSImplemeter.Husk

End Su

End Clas

The problem is that I get an error on the line of code that dimension the objDog. The squiggly line goes under the CSImplementer.Husky and says..

"Reference required to assembly 'DogInterface' containing the implemented interface 'DogInterface.IDog'. Add one to your project.

But...I already added it to the project. Am I missing something here??...or is there a real problem??

BTW...I am using .NET Enterprise Architect version 7
 
K

Kelly Leahy

"Reference required to assembly 'DogInterface' containing the implemented
interface 'DogInterface.IDog'. Add one to your project."
Did you add the reference to the assembly itself, or just the Imports
clause?

You need to reference the .dll itself in your application (see the solution
explorer references folder).

Kelly
 
J

Jay B. Harlow [MVP - Outlook]

Paul,
To reiterate Kelly's comments.

You need to reference BOTH assemblies in your third project, the assembly
where IDog is defined, plus the assembly where Husky is defined

VB.NET does not infer the reference to the IDog assembly from the Husky
assembly, you need to explicitly give the reference to the IDog assembly.

Hope this helps
Jay

Paul said:
OK...I must be missing something...can someone tell me what I'm not doing properly....

First, create an assembly with a single interface in VB.NET as follows

Public Interface IDog
Function Bark(ByVal lVolume As Long) As String
End Interface

Pretty simple...

Now...in a second (C#) assembly...create a class that implements that interface...like so...

using System;
using DogInterface;

namespace CSImplemeter
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class Husky : IDog
{
public string Bark(long lVolume)
{
return "Deep Bark!! at " + lVolume.ToString() + " level";
}
}
}


This is also pretty simple (as you can see...the namespace for the IDog is
DogInterface...that is also the name of it's assembly). This all compiles
very well...I have a single solution with both projects in it.
Now...I create a new assembly...a VB.NET windows application in the same
solution that will use that Husky Class. I have referenced the two
assemblies from above and placed a single button on the form.
In a click event for the test button, I have the following code:

Imports CSImplemeter
Imports DogInterface

Public Class Form1
Inherits System.Windows.Forms.Form

[" Windows Form Designer generated code "]

Private Sub cmdBark_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdBark.Click
Dim objDog As CSImplemeter.Husky

End Sub

End Class

The problem is that I get an error on the line of code that dimension the
objDog. The squiggly line goes under the CSImplementer.Husky and says...
"Reference required to assembly 'DogInterface' containing the implemented
interface 'DogInterface.IDog'. Add one to your project."
But...I already added it to the project. Am I missing something
here??...or is there a real problem??
 
G

Guest

Yes...I have added a reference to both of the assemblies to the test windows project assembly. That is the main frustration behind this one...I added it as a reference, then it tells me to add it as a reference.
 
G

Guest

OK...figured out a way...but it is really strange....my referenece that I was using was via the 'Projects' tab in the 'Add Refereces' functionality. I removed that reference and added a reference that was directly from the .dll that is generated upon compile (using the 'Browse...' button). This worked.

I don't really understand it...I am guessing that a reference to the project created some sort of circular reference because the reference to the Husky implementation also pointed to the project referenece.

Any other gueses anyone!!....well...I did get the solution...thanks for the replies Kelly and Jay!
 
J

Jay B. Harlow [MVP - Outlook]

Paul,
Which version of VS.NET?

I have similar "circular references" in strictly between VB.NET projects in
VS.NET 2003.

I'm curious if VS.NET 2002 is having a problem or if C# in the mix is having
the problem.

Hope this helps
Jay

Paul said:
OK...figured out a way...but it is really strange....my referenece that I
was using was via the 'Projects' tab in the 'Add Refereces' functionality.
I removed that reference and added a reference that was directly from the
..dll that is generated upon compile (using the 'Browse...' button). This
worked.
I don't really understand it...I am guessing that a reference to the
project created some sort of circular reference because the reference to the
Husky implementation also pointed to the project referenece.
Any other gueses anyone!!....well...I did get the solution...thanks for
the replies Kelly and Jay!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top