LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Are static classes of .Net assembly not supported in LabView

We are using a C# dll that contains a couple of static classes. We used LabView 7.1 to load the dll and the static classes did not show up. When we used LabView 8.5 to load the dll the classes showed up but they say that there are no public constructors for the class. I was wondering if LabView supports static .Net classes.
0 Kudos
Message 1 of 6
(8,436 Views)
Hi Priya102,

The behavior you are seeing is related to how we display .NET static classes in the Select .NET Constructor Dialog Box. In LabVIEW 7.1.1 and LabVIEW 8.0, we did not display static classes in that dialog box but in LabVIEW 8.2.1 (I can't remember if it was LabVIEW 8.2 or 8.2.1) we started actually showing the user the static classes. Thus in LabVIEW 8.2.1, you can bring up your static class in the Select .NET Constructor dialog, but you can't click OK because there are no constructors (i.e. which makes sense since we are dealing with .NET static classes).

It is important to note that .NET static classes cannot be instantiated (i.e. you can't create objects but rather you directly access the methods and properties). To call static methods or properties, you
1) Drop down an invoke node or property node from the .NET palette
2) Right-click on the top-left terminal and select
Select Class » .NET » Browse from the shortcut menu to display. Then browse to your .NET assembly and choose your .NET class. 
3) Choose a method or property or your static class.
 

(Note You can invoke static methods if you have an instance - we know it's static and ignore the instance value passed in on the refnum)

Best Regards,
Jonathan N.
National Instruments
Message 2 of 6
(8,432 Views)

We've done as suggested above and are still having problems.  When calling a static method within a static class we are getting an error (1172-Exception has been thrown by the target of an invocation. >> The type initializer for 'CALModel.DataLayer.DAOFactory' threw an exception. >> Object reference not set to an instance of an object. in Test.vi) however when we call a static method within a general class we get no error.  Any ideas?  Are there any examples of calling static methods that we could reference to ensure that we are doing everything correctly on the .net side, specifically using static classes?

Thanks for your help...

0 Kudos
Message 3 of 6
(8,425 Views)
Hi Priya102,

Typically when I am getting .NET exceptions in LabVIEW, I'll go back to C# or VB.NET and test out the assembly there to make sure everything works the way I expect it to.  Static methods and properties should be very easy to call as the mscorlib assembly has a variety of static classes you can test. For example the static String class has a variety of static methods (as shown in the attached snapshot, Class Browser.jpg) shown in LabVIEW with the [S] syntax. The attached snapshot, Code Snippet.jpg shows me calling on the String.Compare static method overloads. 

There is a ton of different reasons why that exception was thrown. I assume the exception was of type System.NullReferenceException? This simply means that some object trying to be accessed is disposed of or set to null.

The best suggestion I can give is to test this is .NET first and then move to LabVIEW. That's the way I also handle those types of issues.

Best Regards,
Jonathan N.
National Instruments
Download All
Message 4 of 6
(8,394 Views)
Hi, I am having the same problems with static class. Did you solve your problem? I'm using a .NET class in my LabView program and can't get it to work. The .NET class is developped by someone else and he says that it works in the native language. But when I try it in LV I get this error code. Since I'm not experienced in C# I can't test it. Any suggestions on what to do next?
0 Kudos
Message 5 of 6
(8,278 Views)
Yes i was able to fix my problem. I made two changes to the C# code. I dont remember which one of them actually fixed the problem.
1) I removed the keyword static from the class signature. The class still had static methods.
2) This probably is not your problem but here goes.....I was using the dll from a web application too (in addition to using it from labview). In the dll i was accessing the connection string to connect to the database from the web.config file. I later realised that labview was erroring out while accessing the connection string since labview has no way of loading the web.config file since this file is something specific to the web app.

My code was also working fine natively, it was giving problems only when i called it from labview which led me to believe that the problem is with labview, but i was wrong. I would strongly encourage the person who developed the C# dll to carefully re-consider all the assumptions he made while testing out the dll and play around it a bit. I am a C# developer and i have no experience with labview, but i just took a few pointers from one of our engineers who knows labview as to how to instantiate a class etc and started testing it out myself changing different things in the C# code. It was frustrating since there was no way of debugging the code (as far as i knew) and figure out where exactly the problem was but it didnt take too long to get it to work. Hope this helps.
Message 6 of 6
(8,273 Views)