NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How to unload a .NET module during runtime (programmatically)

Solved!
Go to solution

I am working on a C# program running in a .NET module in TestStand, so I have Visual Studio and TestStand open. I change/compile my code in Visual Studio and then I try to run my sequence, which calls a method in my C# program.

 

I have the very annoying problem of needing to do File > Unload All Modules, after every time I run my sequence, or else I can't recompile my C# code. I get this error in Visual Studio:
Unable to copy file "obj\Debug\WindowsFormsApp1.exe" to "bin\Debug\WindowsFormsApp1.exe". The process cannot access the file 'bin\Debug\WindowsFormsApp1.exe' because it is being used by another process.

 

How do I unload my .exe (from the .NET modules) at the end of my sequence? I try calling RunState.Engine.UnloadAllModules() in a Statement in my sequence, but it doesn't work.

 

I have attached a dead simple example with a .seq file and a C# file.

 

My problem is compounded by a project I'm working on that has a separate sequence running constantly in the background, in addition to my custom sequence. So when I do File > Unload All Modules, I have to rerun that separate sequence before I can run my custom sequence.

Download All
0 Kudos
Message 1 of 3
(2,150 Views)
Solution
Accepted by topic author Dana517

Have you seen this: https://www.ni.com/en/support/documentation/supplemental/19/unloading--net-assemblies-in-teststand.h...?

Michał Bieńkowski
CLA, CTA, CPI

  1. Did someone devote their time to help solve your problem? Appreciate it and give kudos.
  2. Problem solved? Accept as a solution so that others can find it faster in the future.
  3. Contribute to the development of TestStand by voting on the TestStand Idea Exchange.
0 Kudos
Message 2 of 3
(2,100 Views)

That link did help. The last paragraph mentioned that the Sequence Analyzer can prevent .NET modules from being unloaded.

 

I went to Debug > Sequence Analyzer > Sequence Analyzer Options... -- and in the dialog, I unchecked "Analyze File Before Executing". After that, I stopped needing to click Unload All Modules.

Message 3 of 3
(2,039 Views)