LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Various .NET Problems in LabVIEW 8.5

While developing various .NET objects to be used inside the LabVIEW environment, I tried to do as much unit-testing outside of LabVIEW as possible. However, I've found that various .NET code behaves differently inside the LabVIEW environment thus invalidating all of the unit-testing. Here are the 2 biggest problems:


1. Static data of .NET objects does not persist between VI executions. Is this supposed to happen? If so, is there a way to allow it to persist between VI executions?

Example: Let's say I have the following .NET class with a static variable:

class MyClass
{
    static string MyStaticString = "hello world";
}

If there is VI that constructs an instance of MyClass, then the value of MyStaticString is re-initialized back to "hello world" every time the VI is executed. Is there a way to prevent MyStaticString from being re-initialized per VI execution?


2. .NET type information is not returned correctly inside the LabVIEW environment.

Example: The .NET method Type.GetInterfaces does not actually return an array of interfaces inside the LabVIEW environment.

Let's say I add an interface to MyClass:

interface MyInterface
{
}

class MyClass : MyInterface
{
    ...
}

The call to typeof(MyClass).GetInterfaces() should return a non-empty array containing an element describing MyInterface (that's what it does in a normal .NET environment). Yet in LabVIEW, the call always returns an empty array.


I know these problems are extremely specific, so if anyone knew of a general resource describing the .NET environment inside of LabVIEW and how it behaves compared to a normal environment; that would be a lot of help too.

Thanks in advance!


VRMan


0 Kudos
Message 1 of 2
(2,585 Views)

Hi VRMan,

When a VI terminates execution, it (and, consequently, any .NET objects it references) is garbage collected by LabVIEW and all information is lost.

To avoid this, you could try to store your .NET reference in a shared variable independent of the VI, or simply keep the VI running by placing the block diagram in a while loop.  You can hide the front panel if necessary (see FrontPanelStates.vi in the Help»Find Examples menu).

As for your second question, LabVIEW data types do not directly correspond to those of text-based languages (including .NET).  It is sometimes necessary to first write a wrapper DLL or assembly to convert the .NET data to a format that LabVIEW can process.  In this case, importing an array of Type objects directly would require a significant amount of manipulation within LabVIEW before it would be of any use (if it's even possible).

Eric V
National Instruments
Applications Engineer
Certified LabVIEW Associate Developer


"I'm a Ramblin' Wreck from Georgia Tech and a helluva (NI Applications) Engineer!"
0 Kudos
Message 2 of 2
(2,544 Views)