Return object from C# to Silverlight via COM
I have made a C# COM Visible class that I can access via the
dynamic com = AutomationFactory.CreateObject("MyCom");
function in Silverlight and I am able to return basic datatypes (ie string, int..). So far so good :).
But now I would like to return an object over the COM connection and that proved to be quite difficult. I can return an object and place it into a dynamic variable and from there access the object members, but I can't cast the data to my desired object type.
Questions: 开发者_StackOverflow社区1. Is there a way to cast a dynamic variable to my desired class. 2. Is there a way to make the COM object return an object of my desired class?
The answer to both your questions is: No.
There is no interop between the full version of .NET installed on a client and the Silverlight version of .NET.
The best you can do is create wrapper class that accepts the dynamic
and delegates its members into the dynamic
.
If you want to re-use code that consumes this .NET object in both full .NET and Silverlight then define the object using an interface. Have the original class implement the interface and have the wrapping class also implement the interface.
精彩评论