08-09-2016 03:38 AM
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...
Solved! Go to Solution.
08-09-2016 04:02 AM
I think I solved it:
After posting I found a similar problem which seemed to contain the solution:
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#?