
Signature
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele
That's a great suggestion -- unfortunately, I've already tried it :)
Whether I use the DispId attribute or not, because the property in question
is a C# indexer it appears that regasm always mark it as the default
property whether the DispId attribute is present or not. I've verified this
by looking in the typelib -- I can see that this property has DispId of 0
whether I assign it explicitly or not. Additionally, if I look at the object
in the VB Object Browser, it shows the Item property as default. So, using
DispId in this case seems to be redundant.
I don't know if this is relevant, but the
ClassInterface(ClassInterfaceType.None) at the assembly level so that I can
define my own class interfaces for every class in my project. This has
worked just fine to this point so I've assumed that doesn't have anything to
do with the current problem.
Thanks again -
Ken
> > I have some .NET classes which I intend for possible use with VB 6 (or other
> > COM-compliant language). On some of my objects I have defined a default
[quoted text clipped - 26 lines]
>
> Try setting the DispId attribute on the default method to 0.
Patrick Steele [MVP] - 30 Jun 2004 16:17 GMT
> That's a great suggestion -- unfortunately, I've already tried it :)
>
> Whether I use the DispId attribute or not, because the property in question
> is a C# indexer it appears that regasm always mark it as the default
> property whether the DispId attribute is present or not.
Ok, wasn't sure if it would do that. Neat!
> I don't know if this is relevant, but the
> ClassInterface(ClassInterfaceType.None) at the assembly level so that I can
> define my own class interfaces for every class in my project. This has
> worked just fine to this point so I've assumed that doesn't have anything to
> do with the current problem.
I tried to reproduce your problem and was unable. Here's a quick
snippet of code I used. The only difference I see (based on your
description) is that I define an interface for my .NET classes and
they'll be the default interface since I also have the ClassInterface
(ClassInterfaceType.None) attribute applied to the assembly:
using System;
using System.Collections;
namespace DispIdZero
{
public interface IPerson
{
string FullName { get; set; }
}
public class CPerson : IPerson
{
private string m_Fullname = null;
public CPerson()
{
}
public string FullName
{
get { return m_Fullname; }
set { m_Fullname = value; }
}
}
public interface IPeople
{
IPerson this[string index]{ get; }
int Count { get; }
}
public class CPeople : IPeople
{
private Hashtable m_People = new Hashtable();
public CPeople()
{
IPerson p;
p = new CPerson();
p.FullName = "Bob Barker";
m_People.Add("BOB", p);
p = new CPerson();
p.FullName = "Mike Meyers";
m_People.Add("MIKE", p);
}
public IPerson this[string index]
{
get
{
return (IPerson) m_People[index];
}
}
public int Count
{
get
{
return 0;
}
}
}
}
Using REGASM (along with the /tlb option) I was able to get the
following VB6 code to work:
Dim people As CPeople
Set people = New CPeople
Debug.Print people.Item("BOB").FullName
Debug.Print people("BOB").FullName
Dim op As Object
Set op = New CPeople
Debug.Print op.Item("MIKE").FullName
Debug.Print op("MIKE").FullName

Signature
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele
DotNetJunkies User - 16 Sep 2004 22:06 GMT
Try adding the [DispId(0)] attribute to the actual get and set methods.
---