My C# code has a struct
which I am exporting to COM. The properties of this struct are coming through with strange names that aren't even valid syntax in VB6, so they cannot be accessed.
Is there some way to get these to export with normal, usable names? Am I missing an attribute or something?
The format of the name in COM / VB6 is:
<original_name>k__BackingField
where only the original_name
part was in my C# code.
I can only see these crazy property names in the VB6 Object Browser, Intellisense won't show it.
Here's the (slightly sanitized) code which is being built:
[Guid("....")]
[ComVisible(true)]
public struct MyStruct
{
public string StringA { get; set; }
public string StringB { get; set; }
public MyStruct(string a, string b)
{
StringA = a;
StringB = b;
}
... // some other methods, no fields or properties
}
and for good measure here is the IDL that gets generated:
typedef [uuid(....), version(1.0), custom(xxxx, MyNamespace.MyStruct)]
struct tagMyStruct {
LPSTR <StringA>k__BackingField;
LPSTR <StringB>k__BackingField;
} MyStruct;
as shown by OleView. I can see it contains the same k__BackingField
as noted above. So it seems these names are coming from the C# typelib export process.