C# class not implementing VB.NET interface

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paul

    #1

    C# class not implementing VB.NET interface

    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...crea te a class that implements that interface...lik e 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.ToStrin g() + " 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(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles cmdBark.Clic

    Dim objDog As CSImplemeter.Hu sk

    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.H usky and says..

    "Reference required to assembly 'DogInterface' containing the implemented interface 'DogInterface.I Dog'. 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


  • Kelly Leahy

    #2
    Re: C# class not implementing VB.NET interface

    > "Reference required to assembly 'DogInterface' containing the implemented
    interface 'DogInterface.I Dog'. Add one to your project."[color=blue]
    >[/color]

    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


    Comment

    • Jay B. Harlow [MVP - Outlook]

      #3
      Re: C# class not implementing VB.NET interface

      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" <anonymous@disc ussions.microso ft.com> wrote in message
      news:612A0065-4A00-4F58-8F80-364E73B819D7@mi crosoft.com...[color=blue]
      > OK...I must be missing something...can someone tell me what I'm not doing[/color]
      properly....[color=blue]
      >
      > 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...crea te a class that implements that[/color]
      interface...lik e so...[color=blue]
      >
      > 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.ToStrin g() + " level";
      > }
      > }
      > }
      >
      >
      > This is also pretty simple (as you can see...the namespace for the IDog is[/color]
      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.[color=blue]
      >
      >
      > Now...I create a new assembly...a VB.NET windows application in the same[/color]
      solution that will use that Husky Class. I have referenced the two
      assemblies from above and placed a single button on the form.[color=blue]
      >
      > 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(B yVal sender As System.Object, ByVal e As[/color]
      System.EventArg s) Handles cmdBark.Click[color=blue]
      >
      > Dim objDog As CSImplemeter.Hu sky
      >
      > End Sub
      >
      > End Class
      >
      > The problem is that I get an error on the line of code that dimension the[/color]
      objDog. The squiggly line goes under the CSImplementer.H usky and says...[color=blue]
      >
      > "Reference required to assembly 'DogInterface' containing the implemented[/color]
      interface 'DogInterface.I Dog'. Add one to your project."[color=blue]
      >
      > But...I already added it to the project. Am I missing something[/color]
      here??...or is there a real problem??[color=blue]
      >
      > BTW...I am using .NET Enterprise Architect version 7.
      >
      >[/color]


      Comment

      • Paul

        #4
        Re: C# class not implementing VB.NET interface

        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.

        Comment

        • Paul

          #5
          Re: C# class not implementing VB.NET interface

          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!!....wel l...I did get the solution...than ks for the replies Kelly and Jay!

          Comment

          • Jay B. Harlow [MVP - Outlook]

            #6
            Re: C# class not implementing VB.NET interface

            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" <anonymous@disc ussions.microso ft.com> wrote in message
            news:905AE072-E200-41F9-9F45-6FBF1C23A1B9@mi crosoft.com...[color=blue]
            > OK...figured out a way...but it is really strange....my referenece that I[/color]
            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.[color=blue]
            >
            > I don't really understand it...I am guessing that a reference to the[/color]
            project created some sort of circular reference because the reference to the
            Husky implementation also pointed to the project referenece.[color=blue]
            >
            > Any other gueses anyone!!....wel l...I did get the solution...than ks for[/color]
            the replies Kelly and Jay!


            Comment

            Working...