LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I pass by reference .NET parameters in LV?

Hi, just a couple quick questions related to .NET interaction:
1) If I have a class method that uses value types passed by reference:
 
int MyMethod(ref int myParam);
 
How do I invoke this method in LabView?  The invoke node specifies the type of myParam as a .NET Refnum.  I have tried using another Invoke node to create a reference to a System.Int32 object (Int32 has no constructor) and pass the Int32 Invoke node reference to myParam.  This, however, doesn't work (it creates "class conflict":).  Wiring an I32 type LV control doesn't work either.  This seems pretty simple, and I'm probably missing something obvious, but I can't figure out how to do it.
 
2) Is checking for error 1172 the only way to catch .NET exceptions in LV?  Is it possible in any way to get an instance of the exception type with access to the properties of that exception type?  I assume that the source field in the error cluster contains the Message property of the execption, which could be parsed out of the string, but is there any way to access other information that might be contained in the exception?
 
Thanks,
Matt
0 Kudos
Message 1 of 4
(3,316 Views)
1. You've run into an error in LV when dealing with references. The way to work around it is to use the "To Object" and "To Variant" VIs that are in vi.lib\Platform\dotnet.llb. Thus you take your integer and then pass it through "To Object" - this boxes it (using .NET terms) and you can pass it to the routine. You then use the To Variant to get the value back into LV.
 
2. The 1172 error code does indicate that we received a .NET exception from the API that you called but in 7.1 that is the only information that is available. I'm afraid there isn't any way to get access to the exception that was caught.
0 Kudos
Message 2 of 4
(3,308 Views)
Regarding #2, does anyone know if they fixed that in Labview 8?  .net has lots of specific error messages that'd make it easier to troubleshoot so why Labview would just combine them into one exception message doesn't seem very user friendly.
Doug Asselbergs
Certified LabVIEW Developer
0 Kudos
Message 3 of 4
(3,253 Views)
There are two solutions to the issue.
 
First is that we now put the .NET Exception Message property into the error source string in the error cluster. This will let you get the specific message from the error condition.
 
Second, for advanced users (mainly debugging .NET code you wrote and are calling from LabVIEW), is that the full ToString information from the exception is sent to the Windows debug stream. This is more advanced because it provides you with the full stack trace of the exception - useful only if you have the source code and can do something about it. The easiest way to see this is with a tool that captures that information, such as from SysInternals (www.sysinternals.com, look for Debug View - not a formal recommendation from NI, simply the tool I use personally)
 
IMPORTANT NOTE - The second solution is not a supported or documented feature, therefore it is not certain that it is going to be there in future versions.
0 Kudos
Message 4 of 4
(3,242 Views)