I am trying to export a class in LabVIEW 2013 to a .NET Assembly. According to this I can just select the members of the class that I want to export and it will generate a .NET class for them.
I am able to export the individual members of the class, but when I run the code in .NET it starts searching for mydllname.dll/myclassname.lvclass (the file of the class that the exported members belong to) and can't find it. My next step was to add the class to the the Always Included list, but it seems that when I do that some of the members that I have in the Exported VI's list don't show up in the .NET assembly. The class I'm trying to export is inhereted from another class, so I tried adding both classes to the Always Included list and all of the base class members to the Exported VI's list, but I still have members missing in the .NET classes. Thinking it could be something releated to exporting LVOOP classes, I tried ditching the LVOOP class altogether and rewrote the labview code to use generic VI's and a cluser typedef to store the member data. However, it seems like the labview builder doesn't recognize that the control and indicator clusers that I use to pass the member data belong to the same typedef, so it exports a different .NET class for each control and indicator cluster. This creates a problem because I have no way of passing the output of one funtion to the next in .NET since I cannot convert between the two .NET types.
Has anyone had problems like this/know how to fix it??? I couldn't find much online about building a .NET interop assembly beyond the basic configuration steps, so any help would be much appreciated!
Ok, so now I've tried building the .NET interop assembly by only exporting the members that I need and not including anything in the Always Included list. Like before, all of the members show up when I don't have anything in the Always Included list. I found that if I didn't try to instanciate the object in .NET, then I wouldn't get the search box that appeared before. As a workaround to actaully instantiate the object, I created a constructor in LabVIEW, which is basically just a VI that outputs a constant object of the class, and exported that to the .NET interop assembly. Calling the workaround constuctor within .NET returns an object of the class, but when I try to pass that object to another member I get the followning exception:
"Failed to convert the LV Class to the .NET class because LV cannot get the LV Class Instance"
NationalInstruments.LabVIEW.Interop.VIAssemblyException was unhandled
Message=Failed to convert the LV Class to the .NET class because LV cannot get the LV Class Instance.
at NationalInstruments.LabVIEW.Interop.DataMarshal.MarshalInputLVClass(IntPtr entryPointDataSpace, LVClassRoot value, Int32 terminalIndex, IntPtr lvClient)
at SXI1088CommunicationInteropAssembly.SXI1088SerialInterfaceLib.SXI1088SerialInterface_DAQmx.Initialize(SXI1088SerialInterface_DAQmx sXI1088SerialInterface_DAQmx__32in, SXI1088SerialInterface_DAQmx& sXI1088SerialInterface_DAQmx__32out)
at SXI1088_ClassLibrary.SXI1088SerialInteface_DAQmxWrapper.Initialize() in D:\Visual Studio 2010\Projects\SXI1088 EEPROM Interface\SXI1088 EEPROM Interface_V2_4\EEPROM_Tester\SXI1088_ClassLibrary\SXI1088SerialInteface_DAQmxWrapper.vb:line 21
at SXI1088_ClassLibrary.SXI1088_ClassLibrary.Initialize() in D:\Visual Studio 2010\Projects\SXI1088 EEPROM Interface\SXI1088 EEPROM Interface_V2_4\EEPROM_Tester\SXI1088_ClassLibrary\SXI1088_ClassLibrary.vb:line 93
at TestApp.Form1.Button1_Click(Object sender, EventArgs e) in D:\Visual Studio 2010\Projects\SXI1088 EEPROM Interface\SXI1088 EEPROM Interface_V2_4\EEPROM_Tester\TestApp\Form1.vb:line 4
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String commandLine)
at TestApp.My.MyApplication.Main(String Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String args)
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
How big of a class are you trying to export? Does the private data contain any typed defined controls?
I will see if I can generate the same error.
The class is not very large, only 7 methods total and about 10 membes in the private data, some of which are typed defined controls. I only need to export three of the methods, but I've tried exporting everything, but I'm having the same problems...
Thanks a lot for taking a look at this!
You mentioned you had inheritance. What does the Hierarchy look like? How many parent and grandparent classes do you have? If you are unsure you can Right Click the class in the project explorer and select Show Class Hierarchy.
I am able to make a simple LabVIEW Class and turn it into a .NET Assembly. Now I am working on the inheritance portion of the problem. I still have not replicated the error.
Interesting that you don't see the error. The inheretance looks like this:
SXI1088SerialInterface_DAQmx.lvclass <=== this is the class I'm trying to export
I don't think it should matter, but both classes are inside a lvlib as well. I've tried added the parent classes to the Always Included list, but it seems that whenever I add something to that list some of the exported methods are missing from the .NET assembly...
I am able to reproduce your first error of .NET searching for the class. This only happens when I export a class or VIs that have white space or does not conform to the .NET framework rules for classes and functions. LVOOP allows for class names to have white space. Is the class you are trying to export SXI1088SerialInterface_DAQmx.lvclass or SXI1088SerialInterface DAQmx.lvclass?
The class is called SXI1088SerialInterface_DAQmx (with the underscore and no whitespaces). Some of its method names contained whitespace in them, so I removed the spaces and rebuilt, but I still get the search box whenever I try to instantiate the object. I also defined a method in LabVIEW that just returns a constant of the class to use as a constructor, but when I do that I get this error:
"Failed to convert the LV Class to the .NET class because LV cannot get the LV Class Instance."
Can you post screen shots of the build settings? Also is the Rename File in Build option been selected for the classes?
Were you ever able to get to the bottom of this error? I'm having the same issue. I've simplified my code down to a very basic lvclass and still get an exception thrown anytime there's both an input and output of a class as you've shown.
Using LV2013, VS2013, .NET 4.0.
I've created the lvclass Vehicle, which has 3 methods:
I call this from a simple C# console application:
VIE.LVClassTest.Vehicle testVehicle; VIE.LVClassTest.Vehicle.initializeVehicle(out testVehicle); VIE.LVClassTest.Vehicle.setMakeModel(testVehicle,"VW","Golf",out testVehicle); string vehicleName =""; VIE.LVClassTest.Vehicle.getVehicleFullName(testVehicle,out vehicleName,out testVehicle);
I get a VIAssemblyException at the setMakeModel function saying: "Failed to convert the LV Class to the .NET class because LV cannot get the LV Class Instance." The function initializeVehicle works fine.
As a test, I also tried calling the .NET assembly in LabVIEW:
I also get the same exception thrown at the setMakeModel invoke node. Probing the outputs for the functions, initializeVehicle returns a valid refnum, however setMakeModel returns a null refnum.
Any thoughts? Thanks!
(Also cross-posted as a reply to another thread on LAVA here: http://lavag.org/topic/16652-events-from-within-net-interop-assemblies/?p=108743 )