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.

VBA object browser doesnt list C# class methods.

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

I have already posted a related question on this group, may be the
answer to this question is linked to the answer to other question, but
I think its not related. I have added the link to other question at the
end of this post.

Coming to the issue I am facing:
I am using Visual Studio.NET 2005 beta 2 (.net framework 2.0 beta).

I have a class definition like this:
       [ComVisible(true)]
       public  class Class1
       {
               private int i;
               public int Method1()
               {
                       return i;
               }
       }

I build the assembly and then I add as reference using the the tlb file
for this assembly in Excel VBA. When I navigate to object browser in
VBA and search for "Class1" I see it there but the public method
"Method1" is not listed. When I use the method in VBA code though it
works fine.

The problem is :users will face the issue of not knowing what methods
are available through this class.

I have one solution when I make the class implement an interface and
set ClassInterface attribute to none, thereby the methods are listed as
part of the interface.

Is it the correct approach?
Is there a better approach?
Is it going to cause issues with versioning ie., is it going to break
user code when we release a new version of this class or any other
issue?

thanks in advance
link to other question:
http://groups.google.com/group/microsoft.public.dotnet.framework.interop/browse_
thread/thread/9c80a794000c5848/ae929e018f389d6c#ae929e018f389d6c

Robert Jordan - 07 Oct 2005 05:02 GMT
> I have one solution when I make the class implement an interface and
> set ClassInterface attribute to none, thereby the methods are listed as
> part of the interface.
>
> Is it the correct approach?

Yes

> Is there a better approach?

Hmm, ClassInterfaceType.AutoDispatch. I don't get it why it doesn't
work for you under .NET 2.0. Maybe isn't the default value anymore.

> Is it going to cause issues with versioning ie., is it going to break
> user code when we release a new version of this class or any other
> issue?

As usual with COM interfaces: never change them after a public release.

Rob
Zdenek Drlik - 07 Oct 2005 14:46 GMT
>> I have one solution when I make the class implement an interface and
>> set ClassInterface attribute to none, thereby the methods are listed as
[quoted text clipped - 8 lines]
> Hmm, ClassInterfaceType.AutoDispatch. I don't get it why it doesn't
> work for you under .NET 2.0. Maybe isn't the default value anymore.

I think that using ClassInterfaceType instead of explicitly declaring
own interface for class is not better approach. MSDN section
"Introducing the Class Interface":

Using the class interface, instead of explicitly defining your own, can
complicate the future versioning of your managed class. Please read the
following guidelines before using the class interface.

So if you could define own interface for class, do it and set the
ClassInterface to None. It is better and recommended approach:

[C#]
[ClassInterface(ClassInterfaceType.None)]
public class LoanApp : IExplicit {
    void M();
}

Zdenek D.
Robert Jordan - 07 Oct 2005 15:06 GMT
Hi Zdenek,

>> Hmm, ClassInterfaceType.AutoDispatch. I don't get it why it doesn't
>> work for you under .NET 2.0. Maybe isn't the default value anymore.
[quoted text clipped - 15 lines]
>     void M();
> }

ClassInterfaceType.None will not work with strictly late-bound
clients (VBScript, JScript). Since I don't know much about VBA,
I assumed it problably does strict late-binding as well.

ClassInterfaceType.AutoDispatch is the default under .NET 1.1
and it doesn't have the versioning problems of *AutoDual*.

Rob
manohar.shankar@gmail.com - 07 Oct 2005 19:36 GMT
Thanks for the quick response,

by original question still remains:
Why the methods in the class are not listed through object browser of
Excel VBA, and only the class itself is listed?

I have decided to go ahead with ClassInterface.None approach but I have
some classes which are generated and I have no control over where I can
follow this approach but to somehow make the methods of those classes
list in VBA.

Any ideas?

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.