LabVIEW VI Calling .NET Assembly Crashes when Closing VI

Updated Dec 20, 2017

Reported In

Software

  • LabVIEW Professional

Issue Details

I have a LabVIEW VI that is calling a .NET Assembly. The VI seems to load and execute the assembly fine, but when I close the VI, LabVIEW crashes. If I call the .NET assembly outside of LabVIEW in a .NET application, it loads, executes, and unloads without error.

Solution

One potential explanation for this behavior is the fact that LabVIEW loads each .NET assembly into its own Application Domain.

Therefore, to truly test your .NET assembly outside of LabVIEW and to closely mimic the way that LabVIEW handles the assembly, you should also load the assembly into its own Application Domain.

The following snippet in C# outlines the process for calling an Assembly named MyAssembly in a separate Application Domain from an application named ApplicationName:



If your assembly crashes on the call to AppDomain.Unload(appDomain), then it likely indicates that your assembly is not properly disposing of resources. An example of the runtime error is below:



In general, the Dispose() method of the assembly should handle the clean-up of all unmanaged resources. Reproducing this error outside of LabVIEW is sufficient to determine that further troubleshooting should focus on the assembly itself and that the LabVIEW crash is likely not unexpected behavior.

Additional Information

More information on properly writing the Dispose method of your assembly is beyond the scope of this document, but the resources linked below could be a helpful starting point.

WAS THIS ARTICLE HELPFUL?

Not Helpful