LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I create a .NET List?

Solved!
Go to solution

I know this is an old topic but I ran across it while trying to figure out how to use dotNET to set inheritable permissions on directories in Windows and, as near as I can tell, this question of how to create the dotNET constant with the correct datatype for use with the "To More Specific Class function" was never answered.  Just to wrap things up for this discussion, I'd  like to suggest that the following discussion would seen to hold the answer:

https://forums.ni.com/t5/LabVIEW/to-access-function-or-properties-in-sealed-singleton-objects/m-p/23... 

0 Kudos
Message 21 of 30
(1,987 Views)

I have tried all of the methods on here and none of them work for me.  I get Error 1172 which I believe is telling my that I am passing a NULL type to the Activate Invoke node -

 

TrapperDoo_0-1667871718423.pngTrapperDoo_1-1667871875602.png

Is the string typeName that I have listed invalid?

 

0 Kudos
Message 22 of 30
(1,590 Views)

Hi,

have you seen message 15 (https://forums.ni.com/t5/LabVIEW/How-do-I-create-a-NET-List/m-p/3089679#M883437 ) in this thread?

There should be no space in between: System.Collections.Generic.List`1[System.String]

From your picture it seems there is a space in the string.

0 Kudos
Message 23 of 30
(1,573 Views)

There is indeed a space in the string, as you say.  I get the same with and without the spaces, both in the type name and also within the parameters in the square brackets.  I have also have the same problem when I include just [System.String] instead of the full list of parameters in the square brackets.  I think I have tried all combinations for the string format and nothing solves my problem.   Still seems like the type name cannot be found.  Any other ideas?  I am using LV 2017 SP1, BTW.

0 Kudos
Message 24 of 30
(1,540 Views)

Seems that System.Activator needs the type from an active instance? This seems to work....

 

hollowhorse_0-1667928034014.png

 

0 Kudos
Message 25 of 30
(1,521 Views)

Thanks for all of the suggestions, everyone, but none of them have worked.  I still am not able to create a list based on the the string typeName I am using.  My problem is that I need to create a list (type List<String> and then pack a reference to that list to a .NET method.  Are there other string type names I should be trying? 

 

TrapperDoo_0-1668010068945.png

 

I am trying to use the downcast reference to build a list.  Again the System.Type appears to be returning a NULL on the Get Type terminal.

 

0 Kudos
Message 26 of 30
(1,509 Views)

Assuming that the .NET reference constant you have there is a null instance of the actual Generic list you need to create, there is a way to extract the .NET type string programmatically in LabVIEW using the Variant to Flattened String function:

 

Kyle97330_0-1668019178219.png

You could try that just in case there's something different about the type name you need to use on your system compared to the constant string you made.

Message 27 of 30
(1,491 Views)

One thing that's important to note is the apostrophe after the type is not the standard one (0x27) but one with the ASCII value 0x60. I'm guessing this is your issue.

 

Another point is that you can get the assembly info for the internal type using .NET, which should make it somewhat safer. See this example for a dictionary, which has two internal values, but it should be the same for a list:

 

Create .NET dictionary.png


___________________
Try to take over the world!
Message 28 of 30
(1,461 Views)

Yes!  I was wondering about the apostrophe!  I recreated the string using the Ox60 character (alt +96) in place of the regular apostrophe, and the type is now valid and I can now create an instance.  Note it also required NO SPACE between the 0x60 character and the "1".  Thank you very much Good Sir Knight!

 

0 Kudos
Message 29 of 30
(1,429 Views)

To be more specific, it's not actually an apostrophe, but a "grave accent". For a bit more detail, you can see the note in the following link. In general, information about this seems scarce.

 

https://learn.microsoft.com/en-us/dotnet/api/system.type.getinterface?redirectedfrom=MSDN&view=net-7...

 


Note

For generic interfaces, the name parameter is the mangled name, ending with a grave accent (`) and the number of type parameters. This is true for both generic interface definitions and constructed generic interfaces. For example, to find IExample<T> (IExample(Of T) in Visual Basic) or IExample<string> (IExample(Of String) in Visual Basic), search for "IExample1"`.

 


___________________
Try to take over the world!
Message 30 of 30
(1,423 Views)