12-06-2022 07:10 AM
Hello,
I'm developping a .Net application using TestStand API.
Here are my initializing commands :
private AxApplicationMgr applicationManager = new AxApplicationMgr();
private static Engine engine = applicationManager.GetEngine();
The second line worked only once, but now it throws an InvalidActiveXStateException.
Do you know what this could mean ?
Thank you.
12-06-2022 10:32 PM - edited 12-06-2022 10:33 PM
Hi ismu,
I don't think your code give the right path and you shoud refer the ui example that NI give to do it.
The example is located at C:\Program Files\National Instruments\TestStand XXXX\UserInterfaces\Simple\CSharp
Thanks,
Ricky
12-07-2022 02:24 AM
Hello,
Thank you for your reply.
I used an using NationalInstruments.TestStand.Interop.UI.Ax; at the top of my page, but I tried as you told me and put back NationalInstruments.TestStand.Interop.UI.Ax. I had also tried to put my requests next to InitializeComponents in MainWindow (I'm developping a WPF app, not WinForm as their example), (I tried next because the method InitializeComponent itself is reinitialized when I build the program) but I have not succeeded, I still have the same error.
Do you know if the fact that I use WPF app changes something and the modifications I have to make ?
12-07-2022 07:27 AM
I tried next because the method InitializeComponent itself is reinitialized when I build the program
I am not sure how you write the code, but I guess it's not WPF issues. Maybe advice that you can run the example code in Winform to verify it and should only do objection to have applicationManager one time in InitializeComponent (or maybe in Form_Load ???), not sure what you mean "reinitialized" ~
12-07-2022 07:31 AM
In winform the example code worked, and I read my error came from something WPF did not have but Windows.Form had.
I meant the "InitializeComponent" method did not take into account any change I try to make to it, it does not change, so I tried to do it in MainWindow, after "InitializeComponent".
12-07-2022 04:35 PM
Can you confirm that you use single thread apartment with WPF?
12-08-2022 02:28 AM - edited 12-08-2022 02:29 AM
Hello,
I think so yes, here is my code. The second jpg corresponds to my class Parameters, containing variables and methods used with TestStand.
I tried to use it differently from what I described earlier, I tried to do it more like National Instruments example code.
In red, the execution throwing the exception.
I'm not sure how to check whether I'm using STA but I believe it is the case.
12-08-2022 06:48 AM
I added this in MainWindow, but I still have the same error :
public MainWindow()
{
Thread.CurrentThread.SetApartmentState(ApartmentState.STA);