LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Error when loading .NET assembly that references an enum defined in another assembly

Using LabVIEW 8.5, I am attemtping to load an assembly that uses enums that are defined in two other assemblies. The assembly that I am loading fully dereferences the enums with the name of the enum in this format: "namespace.class.enum". The referencing assembly also includes the appropriate "using" clauses, and when the referencing assembly is built, the assemblies that provide the enums are copied to the build directory of the referencing assembly.

In LabVIEW, if I start out with a blank vi, here's what happens. I place a .NET constructor node on the block diagram. I select the assembly and select the appropriate constructor. LabVIEW acts as if it has loaded the assembly, however, the constructor node does not contain the of the referenced class. I then choose "select constructor" again. I select the class, and the appropriate constructor. Finally, LabVIEW appropriately references the class that I am trying to create in LabVIEW.

Now, I save the VI, and exit LabVIEW. When I restart LabVIEW and then reload the vi, LabVIEW indicates and error with the vi by "breaking" the "go" button. If I then look at the constructor node, there is a message in the window that says, "an error occurred trying to load the assembly."

Using dbgview, I see alternately one of two different exceptions that indicate that LabVIEW is unable to find the defintion of the two different enums. Here is the exact exception message from LabVIEW as displayed in dbgview:

[2428] System.TypeLoadException: Could not load type 'SwitchScanMode' from assembly 'OCC_Adapter, Version=1.0.1.0, Culture=neutral, PublicKeyToken=9f4c5abfb8486b52'.
[2428]    at System.Reflection.Assembly.GetExportedTypes()
[2428]    at NationalInstruments.LabVIEW.DNReflect.ListNameSpaces(Assembly assembly, Int32 flags, LVAssemblyInfo* pAsmInfo)
[2428]    at NationalInstruments.LabVIEW.CrossDomainServer.DNListClassesInAssembly(LVAssemblyInfo* pAsmInfo, Int32 flags)

So, it looks like LabVIEW is able to load the assembly at least once. So in some cases, things must be happening properly. However, once the assembly is loaded, if I save the vi, then LabVIEW is never able to load the assembly again.

Anyone else see this? Is there a work around?

Thanks.

0 Kudos
Message 1 of 5
(5,077 Views)
Hi Matthew,

Try adding your VI to a LabVIEW project and then put the assemblies in the LabVIEW project directory or any of its subdirectories. Then open that VI from the project, drop down a .NET Constructor Node, and see if you can see if you can select your public constructors.

We suggest VIs that are using .NET assemblies be part of the project and that you place your .NET assemblies (the ones that are private as the public ones should be in the GAC) in the same directory as the LabVIEW project or in any of its subdirectories.

Let me know if that works!

Best Regards,
Jonathan N.
National Instruments
0 Kudos
Message 2 of 5
(5,070 Views)
Hi Jonathan,

Thanks for your reply. That did the trick!!
0 Kudos
Message 3 of 5
(5,054 Views)
Glad it works Matthew.

Good luck with future projects!

Best Regards,
Jonathan N.
National Instruments
0 Kudos
Message 4 of 5
(5,047 Views)
Hello,

I've fall into this post because I had the same problem. And it became solved with the procedure mentioned here.
But I've another problem....

I'm developing a small .dll using visual studio 2008 and I can use it in my labview application. But everytime I change the dll those changes don't appear on labview.

Any tips?
Software developer
www.mcm-electronics.com





PORTUGAL
0 Kudos
Message 5 of 5
(4,834 Views)