From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing contents of a PropertyObject reference in C# fails

Solved!
Go to solution

I try to access the dynamic contents of a PropertyObject in C# to search its subproperties. I can access the reference object itself, but not its (dynamic) subproperties.

To be more concrete, it's an event handler for the UIMessage ModelState_PostProcessingComplete. That means the sequence context is within "ModelSupport.seq / Call UUT Done/Batch Done".

I try to use the object reference "Parameters.MainSequenceResult" to search for the first failed step and evaluate the stepname. This information is used to detect repeated errors in a custom user interface.

 

Just for testing, I tried the same directly in this sequence using expressions and it works. It seems that the .Net code is not able to follow the aliased contents.

This is the C# code I use:

 

SequenceContext seqc;
SearchResults search;
PropertyObject searchStart;
[...]
if (seqc.Parameters.Exists("MainSequenceResult", 0)) { searchStart = seqc.Parameters.GetPropertyObject("MainSequenceResult", PropertyOptions.PropOption_NoOptions);
search = searchStart.Search("", "True", //search string SearchOptions.SearchOptions_MatchCase | SearchOptions.SearchOptions_WholeWordOnly, //search options SearchFilterOptions.SearchFilterOptions_All, //search filter options SearchElements.SearchElement_BooleanValue, //search element type null, //limit to adapters new string[] { "StepCausedSequenceFailure" }, //limit to named properties null, //limit to properties of named type null); //subproperty strings to exclude
search.IsComplete(true, true); if (search.NumMatches >= 1) {
//this never happens... }
... }

The code executes without error but with no search results. The equvalent code within in a TestStand sequence finds the correct 4 search results.

If I use MainSequenceResult.TS (which exists at runtime) I get a COM Expetion "Unknown variable or property name 'TS'."

 

It works also in C# if I use a non-referenced property like this one:

searchStart = seqc.Parameters.GetPropertyObject(string.Format("ModelData.TestSockets[{0}].MainSequenceResults.TS", myIndex), PropertyOptions.PropOption_NoOptions);

But I want to avoid this, because then I need to know which model is used.

I hope someone can explain the difference or what I'm doing wrong...

0 Kudos
Message 1 of 2
(3,344 Views)
Solution
Accepted by topic author alex_bauer

I think I solved it:

After posting I found a similar problem which seemed to contain the solution:

https://forums.ni.com/t5/NI-TestStand/How-to-Access-to-PropertyObject-throught-two-referenced-object...

I changed my code to

searchStart = seqc.Parameters.GetPropertyObject("MainSequenceResult",0).GetValInterface("", 0) as PropertyObject;

and this worked!

To the experts: is it the correct solution or is there an easier way to dereference object references in C#?

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