Expose System.Uri to COM

  • Thread starter Thread starter maxim
  • Start date Start date
M

maxim

Hi,

I have a Class in C# that exposes property from System.Uri type.
I want to access this property from classic Visual Basic.

[ComVisible(true)]
[ClassInterface(ClassInterfaceType.AutoDual)]
[Guid("C80CFADD-F676-4df6-8499-5C4F2E3434A5")]
public class TestClass
{
public TestClass()
{
}
public Uri MyUri
{
get
{
return new Uri("http://www.test.com");
}
}
}
Now I write in Visal Basic following code:

Dim oTestClass As New TestClass
If Not oTestClass.MyUri Is Nothing Then
'!!! I got "Type Mismatch" error here
'!!! I tried oTestClass.MyUri.ToString CStr(oTestClass.MyUri)
'!!! but result is that ToString is not exists and CStr also Type Mismatch
MsgBox oTestClass.MyUri
End If

Is there any way to do this?

Thanks,
Maxim.
 
You would have to run TLBEXP on System.dll, and export that class.
However, I don't know that this is a good idea, since you would end up
exporting the whole library (and that's a pretty big library). Rather, you
should probably expose this property as a string, and then use that.

Hope this helps.
 
Hi Nicholas,

First of all thank you for fast reaction. I tried your suggestion, but
it did not help. I looked into the type library that TLBEXP exported from
System.dll, but surprised to know that there is no word about System.Uri.
I think that the problem is not connected to System.dll at all.
I mean if I for example expose property of System.Collections.ArrayList type
then I see it in classic Visual Basic and can work with it without TLBEXP of
no .NET dlls (for example I can see ArrayList.Count and it gives me a right
value). So in my opinion there is something special in System.Uri class.
If you will look into object browser, then you will see that it inheritted
from MarshalByRefObject. Please let me know if you have some idea?

Thank you again,
Maxim.



Nicholas Paldino said:
You would have to run TLBEXP on System.dll, and export that class.
However, I don't know that this is a good idea, since you would end up
exporting the whole library (and that's a pretty big library). Rather, you
should probably expose this property as a string, and then use that.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hi,

I have a Class in C# that exposes property from System.Uri type.
I want to access this property from classic Visual Basic.

[ComVisible(true)]
[ClassInterface(ClassInterfaceType.AutoDual)]
[Guid("C80CFADD-F676-4df6-8499-5C4F2E3434A5")]
public class TestClass
{
public TestClass()
{
}
public Uri MyUri
{
get
{
return new Uri("http://www.test.com");
}
}
}
Now I write in Visal Basic following code:

Dim oTestClass As New TestClass
If Not oTestClass.MyUri Is Nothing Then
'!!! I got "Type Mismatch" error here
'!!! I tried oTestClass.MyUri.ToString CStr(oTestClass.MyUri)
'!!! but result is that ToString is not exists and CStr also Type
Mismatch
MsgBox oTestClass.MyUri
End If

Is there any way to do this?

Thanks,
Maxim.
 
Back
Top