Hi,
I have a COM component which calls methods on a .NET object. However, some
methods originate in an inherited interface. COM cannot "see" the inherited
methods.
In the code fragment below, if a COM component creates an instance of Child
class, it cannot "see" the property ParentKey.
Am I missing something? Is there a way around this? Do I have to duplicate
methods and properties in the child class/interface that are inherited from
the parent, for COM to "see" them?
Regards
Gem
---- .NET Code fragment ----
public interface IParent {
string ParentKey { get; set; }
}
public class Parent : IParent {
private string key = "";
public string ParentKey {
get {
return this.key;
}
set {
this.key = value;
}
} // public string ParentKey...
}
public interface IChild : IParent {
string ChildKey { get; set; }
}
public class Child : Parent {
private string childKey = "";
public string ChildKey {
get {
return this.childKey;
}
set {
this.childKey = value;
}
} // public string ChildKey...
}
---- COM code fragment ----
Dim childObject as ChildParentNet.Child
Dim child as ChildParentNet.IChild
Set childObject = new ChildParentNet.Child
set child = childObject
Both child.ParentKey and childObject.ParentKey throw a 438, "Object doesn't
support this property or method" exception.
Gem
Robert Jordan - 16 Sep 2005 11:52 GMT
Hi Gem,
> public interface IChild : IParent {
> string ChildKey { get; set; }
> }
>
> public class Child : Parent {
BTW, you forgot to inherit from IChild.
I never programmed with VB6, thus I don't know whether it
uses late-binding or early-binding.
Your code is ok for late-binding but it won't work
for early-binding clients. For those clients you
must apply
[ClassInterface(ClassInterfaceType.None)]
to your class declarations.
On the other way, setting ClassInterfaceType.None doesn't work
with late-binding clients, so if you want to support both
kind of bindings, you have to use ClassInterfaceType.AutoDual.
See
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cp
conIntroducingClassInterface.asp
Be aware about the implications of using ClassInterfaceType.AutoDual:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlr
fsystemruntimeinteropservicesclassinterfacetypeclasstopic.asp
Rob
Gemma M - 16 Sep 2005 16:23 GMT
Thanks for the info.
Gem
> Hi Gem,
>
[quoted text clipped - 30 lines]
>
> Rob