Dealing with .NET arrays and MarshalByRefObjects
1 次查看(过去 30 天)
显示 更早的评论
I'm using an API from an Audio Precision to detect the available channels from an ASIO device. The API outputs a .NET array of type IChannelInfo[] that I can't seem to get information from. If I create the array as chanInfo and try to access the first object either with chanInfo(1) or chanInfo.GetValue(1) or any other number of Methods, it just returns a "MarshalByRefObject" with no properties that I can't figure out how to actually use. I would expect it to either just return a string like "Analog 2 (1)" or to return another .NET object that includes the name, channel number, etc.
0 个评论
回答(1 个)
Garmit Pant
2024-8-9
Hi Brian,
The issue you are encountering is because ‘IChannelInfo’ is an interface of the ‘ObjRef’ class. An ‘ObjRef’ is a serializable representation of an object that extends 'MarshalByRefObject' (MBR). The ‘ObjRef’ contains information that describes the Type and class of the object being marshaled, its exact location, and communication-related information on how to reach the remoting subdivision where the object is located.
To use an ‘ObjRef’, it first needs to be unmarshalled. Unmarshalling can be done by deserializing the object on the client side using the 'XmlSerializer' class.
You can create an object of the 'XmlSerializer' class and use it to deserialize the output of your API. The following link details the process of deserialization using XmlSerializer: How to: Deserialize an Object
I hope you find the above explanation and suggestions useful!
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!