ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I create a .NET List?

Solved!
Go to solution

[cross-posted to LAVA]

 

Does anyone know why I can't seem to find the System.Collections.Generic.List object in LabVIEW's "Select .NET Constructor" dialog?

 

I'm trying to create a .NET "List" in LabVIEW (Namespace: System.Collections.Generic, Assembly: mscorlib), similar to how it's done in the text-based code, below.

 

List<string> myList = new List<string>();

 

The problem is that I can't seem to find the Generic List object contstructor anywhere.

 

System.Collections.Generic object under the System assembly (I was only able to find System.Collections.Specialized).  I looked inside the mscorlib assembly and found the System.Collections.Generic object, but the only constructor is for something else.

 

 

 

Thanks for your help.

 

-Jim

Message Edited by Jim Kring on 04-11-2009 05:23 PM
0 Kudos
Message 1 of 30
(22,587 Views)
Solution
Accepted by Jim_Kring

Whew...  I figured it out.  It's possible to create these generic types using reflection (dynamic object creation).

 

Message Edited by Jim Kring on 04-11-2009 06:17 PM
Message 2 of 30
(22,578 Views)

I am curious if this works for lists of object types as well?

 

I am using a customer provided API, and unfortunately most of the functions return a generic rtnObject that needs to be converted into the function specific data type. The non list returns were straightforward to convert but the list ones are providing a challenge.

 

Will I be better off just writting my own companion c# dll to convert these custom data types into something labview can more easily recognize?

 

sample C#

public override GatewayReturn GetLatestReads(
     uint gateway_id
)

Return Value
GatewayReturn with rtnObject as List of TransmitterReadMessageItem

 

 

0 Kudos
Message 3 of 30
(22,025 Views)

 

 


@Jim Kring wrote:

Whew...  I figured it out.  It's possible to create these generic types using reflection (dynamic object creation).

 

Message Edited by Jim Kring on 04-11-2009 06:17 PM

 

Jim, 

 

I neither have the System.Type NOR the System.Activator classes / methods available with the .NET 2.0 framework.  

I can see that these are static classes (no constructor), but when I search System (2.0.0.0), I don't see classes or methods for System.Type or System.Activator.  I also don't see System.Type or System.Activator as assemblies.  MS .NET help tells me that System.Collections.Generic IS a namespace I should be able to see, but I dont.

 

I CAN see System.Collections.Specialized, but NOT System.Collections.Generic.

 

If I need to "force" labview to recognize this method using reflection, that's fine, but I can't even find the System.Type or System.Activator calls.

 

Specifically, what did you select when you configured these .NET invoke nodes?

 

Also, the string "System.Collections.Generic.List`1[System.String]" seems to have both special nomenclature and formatting.  From where did you get the information on how to format this string to invoke this method?

 

Just a little lost here.....

 

Thanks, 


Wes

 


--------------------------------------------------------------------------------------
Wes Ramm, Cyth UK
CLD, CPLI
0 Kudos
Message 4 of 30
(21,776 Views)

System.Type and System.Activator are definitely part of .NET 2.0. Both these classes are sealed classes, not static classes.

 

In order to select a static method that a class may expose you need to:

  1. Place a .NET Invoke Node on the block diagram (forget the Constructor node).
  2. Right-click on the Invoke Node and go to Select Class -> .NET -> Browse.
  3. In the dialog box select "mscorlib" from the "Assembly" dropdown menu.
  4. Double-click on "System" to expand it. Scroll down and select "Type".
  5. Click OK.
  6. Now left-click on the Invoke node. A HUGE pop-up menu will display with all of the methods. You'll need to scroll down a bit (having a 60" tall monitor helps here), until you see the GetType methods. The ones you want are the ones that have "[S]" in front of them. These are the static methods. 

The same process holds for the static method for System.Activator.

Message 5 of 30
(21,754 Views)

Hi 

I use system.Type and System.Activator for create  List of point 

but when run it . i see this error 

can you help me ?

 

thanks

M.Garousi
Download All
0 Kudos
Message 6 of 30
(21,495 Views)

The error string tells you the problem: The CreateInstance method threw an error because it was passed a null value. That means the GetType method did not work. It would not work if you passed it an invalid type. Have you verified that's a valid type?

0 Kudos
Message 7 of 30
(21,476 Views)

I think it is true 

 

GetType 2.PNG

M.Garousi
0 Kudos
Message 8 of 30
(21,470 Views)

That doesn't prove anything. The reason why you can do what you are doing on the right-hand side is that you are casting a reference to something else. Try something like this:

 

 

0 Kudos
Message 9 of 30
(21,467 Views)

thanks for your help 

I use " GMap.NET.WindowsForm.GMapPolygon ( [[GMap.NET.PointLatLng, GMap.NET.Core, Version=1.5.5.5, Culture=neutral, PublicKeyToken=b85b9027b614afef]] points , string ) "

I must put List of point , i understand that can do it by use ( system.collections.generic.list ) ,  apparently labview does not support  Generic . 

GetType 3.PNG

M.Garousi
0 Kudos
Message 10 of 30
(21,463 Views)