Dealing with .NET arrays and MarshalByRefObjects

3 ビュー (過去 30 日間)
Brian
Brian 2024 年 8 月 5 日
回答済み: Garmit Pant 2024 年 8 月 9 日
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.

回答 (1 件)

Garmit Pant
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!

カテゴリ

Help Center および File Exchange.NET Enumerations in MATLAB についてさらに検索

タグ

製品


リリース

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by