NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

pass object reference to C#

Hello,

 

as I have read here, more people seem to have a similar problem.

Unfortunately I havent found an answer here, so my question:

 

How can I pass a reference to a object from Teststand to my C# program?

 

In Teststand I am waiting for a event, and when it occurs, I store the event data in a .net object.

Then I pass "ThisContext" with a UIMessage as activeXDataParam to my program, and I get it there as SequenceContext.

Like this: seqContext = (SequenceContext)e.uiMsg.ActiveXData;

Then I try to get my objects with PropertyObjects.

It works well with String objects, but not with the object which I need and get from my event.

I've tried GetValIDispatch, but it seems always to be null.

 

Can anyone help me?

 

 

 

 

 

 

0 Kudos
Message 1 of 2
(3,097 Views)

If you pass a .NET object from a code module to your operator interface you are passing it across appdomains. In order for that to work, the .NET framework requires that your object either be serializable (in which case it will make a new copy in the appdomain it's passed in to), or derived from MarshalByRefObject. Also what version of TestStand are you using? I highly recomment using TestStand 2010 or higher if you are doing a lot with .NET because the .NET adapter was greatly improved starting with TestStand 2010. If you are using TestStand 2010 or higher, you can call GetValInterface on the object reference variable which stores your .NET object to pull it into the appdomain of your user interface (object must be serializable or dervived from MarshalByRefObject). You should also make sure that the assembly which defines the class for your object is either in the same directory as your executable or in the GAC, otherwise you will get an error that the assembly cannot be found/loaded when the object is passed across appdomains. There are otherways to workaround the load issue with an AssemblyResolve event handler, but that is more complicated.

 

I also recommend doing some reading on MSDN (Microsoft Developers Network) for more details about issues with cross appdomain objects, serialization, and other .NET specific issues.

 

Hope this helps,

-Doug

0 Kudos
Message 2 of 2
(3,083 Views)