NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

C# .Net ApplicationManager.GetEngine() throws an exception

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.

0 Kudos
Message 1 of 8
(1,133 Views)

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

Ricky_76_0-1670387428820.png

 

Thanks,

Ricky

0 Kudos
Message 2 of 8
(1,100 Views)

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 ?

0 Kudos
Message 3 of 8
(1,073 Views)

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" ~

0 Kudos
Message 4 of 8
(1,055 Views)

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".

0 Kudos
Message 5 of 8
(1,050 Views)

Can you confirm that you use single thread apartment with WPF?

Michał Bieńkowski
CLA, CTA

Someone devote his time to help solve your problem? Appreciate it and give kudos. Problem solved? Accept as a solution so that others can find it faster in the future.
Make a contribution to the development of TestStand - vote on TestStand Idea Exchange.
0 Kudos
Message 6 of 8
(1,039 Views)

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.

Download All
0 Kudos
Message 7 of 8
(1,023 Views)

I added this in MainWindow, but I still have the same error :

 

public MainWindow()
{
Thread.CurrentThread.SetApartmentState(ApartmentState.STA);

0 Kudos
Message 8 of 8
(1,018 Views)