Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / October 2005

Tip: Looking for answers? Try searching our database.

methods from super interface not availabe through ComVisible interface

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
manohar.shankar@gmail.com - 07 Oct 2005 02:01 GMT
Hi,

I have a pretty basic issue when I am trying expose a C# interface for
COM interoperability. Here is the interface definition:

       [ComVisible(true)]
    public interface IClass:IClassBase
    {
        int IClassMethod();

    }

and the super interface looks like:
    public interface IClassBase
    {
        string IClassBaseMethod();

    }

The implementing class:
       [ComVisible(true)]
    public  class Class1: IClass
    {
        public int IClassMethod()
        {
            return 6;
        }
        public string IClassBaseMethod()
        {
            return "6String";
        }
       }

I build the assembly and then I add as reference using the the tlb file
for this assembly in Excel VBA. There I am trying to write code as:
Dim Iclass As Iclass
Set Iclass = New class1

MsgBox Iclass.IClassMethod       'this call is ok
Msgbox Iclass.IClassBaseMethod  'This fails.

The second call to IClassBaseMethod fails saying the method not
available on interface. I expected .NET framework to handle exposing of
super interface methods automatically. What is wrong with the above
code. How can force the base interface methods to be exposed.

Thanks in advance for taking your time to answer the question.
Robert Jordan - 07 Oct 2005 02:39 GMT
Hi,

> I build the assembly and then I add as reference using the the tlb file
> for this assembly in Excel VBA. There I am trying to write code as:
[quoted text clipped - 8 lines]
> super interface methods automatically. What is wrong with the above
> code. How can force the base interface methods to be exposed.

Both interfaces are exposed. This is the default behavior.
Did you use some other interop attributes you omited before
posting the code? Like

[ClassInterface(ClassInterfaceType.None)] on your class?

Rob
manohar.shankar@gmail.com - 07 Oct 2005 03:07 GMT
No,

I just checked my code and made sure there is no
[ClassInterface(ClassInterfaceType.None)]  on the class "Class1", I can
only define it on the class and not on interface anyway.

I tried that approach for the class class1 but even then the IClass has
only the method exposed from within itself and not the one from base
interface. Please try building this code into a simple assembly
project, you should see the same behaviour. Btw I forgot to mention the
version of .net in original post.

Its Visual Studio.NET 2005 beta 2 (.net framework 2.0 beta).

thanks for the quick response.
Robert Jordan - 07 Oct 2005 03:20 GMT
> I just checked my code and made sure there is no
> [ClassInterface(ClassInterfaceType.None)]  on the class "Class1", I can
[quoted text clipped - 7 lines]
>
> Its Visual Studio.NET 2005 beta 2 (.net framework 2.0 beta).

Sorry, I don't have access to this version right now.
With 1.1 it's working.

Rob
Zdenek Drlik - 07 Oct 2005 11:18 GMT
> Hi,
>
[quoted text clipped - 43 lines]
>
> Thanks in advance for taking your time to answer the question.

It is the way how tlbexp.exe works, the same as in framework 1.1.
The most straightforward approach is to explicitly re-list the inherited
members of each base interface in the derived type:

public interface IClassBase
{
    string IClassBaseMethod()
}

public interface IClass : IClassBase {
     int IClassMethod();
    new string IClassBaseMethod();
}

public class Class1 : IClass {
 // ...
}

and it should work correctly.

Zdenek D.
manohar.shankar@gmail.com - 07 Oct 2005 19:32 GMT
I thought about this approach but it becomes tedious if lot of
interfaces derive from base interface and beats the purpose of having
inheritance right?

Anyway if thats the only way we can do it then I will do it that way.

thanks for the response

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.