From 11:00 PM CDT Friday, Nov 8 - 2:30 PM CDT Saturday, Nov 9, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From 11:00 PM CDT Friday, Nov 8 - 2:30 PM CDT Saturday, Nov 9, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
10-10-2022 08:50 AM
Hi,
I'm using an .NET assembly and everything goes well except for one method which takes a ReadOnlySpan as a input :
ReadOnlySpan<T> Constructeur (System) | Microsoft Learn
After many atempts with my colleagues we are stuck at creating that.
Any help or valuable idea ?
Thx
Solved! Go to Solution.
10-10-2022 10:42 AM
There's the same problem with List<T>.
Here's how to make a List of Boolean:
Changing that string to your "ReadOnlySpan" should do the trick.
Once the instance is created, you can cast it.
You don't have to get the name from the assembly, but my type (Boolean is just for this example) might be upgraded, and I don't the code to break when it is updated.
10-17-2022 05:52 AM
Hello to all,
I have a similar problem. I also need to fill a System.Collection.Generic.List'1 list. I wanted to test it as described above. Unfortunately, I don't know what reference goes to the Type and Activator method in the example. I hope I can create the red framed reference with it.
I would also appreciate any tips.
Thanks already to all 😉
10-17-2022 07:24 AM
Connect a string constant "System.Collection.Generic.List'1" in the type name input
10-17-2022 07:27 AM
Hello,
I have now found the missing elements, but unfortunately I still do not know what to do.
The method Session.Read expects a reference to a Generic ListElement
(System.Collections.Generic.IList`1[[Softing.Opc.Ua.Toolkit.ReadValueId,Softing.Opc.Ua.Toolkit, Version=1.49.0.7691, Culture=neutral, PublicKeyToken=19132d4dfa11b90e]], mscorlib)
I was hoping that I could create this element using the construct. Unfortunately, I am not getting anywhere here. From the method Activator always comes an error
System.MissingMethodException: Cannot create an instance of an interface.
Does anyone have an idea how to create an instance of the list?
Thanks...
10-17-2022 07:40 AM - edited 10-17-2022 07:43 AM
@T. wrote:
Hello to all,
I have a similar problem. I also need to fill a System.Collection.Generic.List'1 list. I wanted to test it as described above. Unfortunately, I don't know what reference goes to the Type and Activator method in the example.
The type you want...
In the example I've posted, a Boolean.
In your code, the creation of the string seems OK
However, you removed the code that actually creates the object. The while loop prevents 'calculating' the string over and over again (it won't change). (You could go even further and cache the .NET type).
Provided ReadValueID is a System.Object, the attached VI should work. Simply wire the ReadValueID to it.
Note you need to close both ReadValueID (once it's in the list) AND the List<ReadValueID> (once it's passed to Read).
Also note you still need to add the ReadValueID to the list, the VI only creates the type.
EDIT: That crossed...
10-17-2022 07:46 AM - edited 10-17-2022 07:55 AM
@T. wrote:Does anyone have an idea how to create an instance of the list?
You are actually creating the list.
Not sure what you expect if you don't use the result.
The output of the activator should go into the Add method (to the top left, instead of the constant).
However, the constant should be used to cast (to more specific) the output to that type.
@T. wrote:
Hello,
I have now found the missing elements, but unfortunately I still do not know what to do.
The method Session.Read expects a reference to a Generic ListElement
(System.Collections.Generic.IList`1[[Softing.Opc.Ua.Toolkit.ReadValueId,Softing.Opc.Ua.Toolkit, Version=1.49.0.7691, Culture=neutral, PublicKeyToken=19132d4dfa11b90e]], mscorlib)I was hoping that I could create this element using the construct. Unfortunately, I am not getting anywhere here. From the method Activator always comes an error
System.MissingMethodException: Cannot create an instance of an interface.
EDIT:
Sorry I didn't get that. If the Activator returns an error, the rest won't matter.
Not sure what's happening here, but there's little we can do about that.
Without being able to try things, you're basically on your own.
10-17-2022 07:54 AM
Hello,
This is how I would have imagined it. Unfortunately, an error always comes out of the CreateInstance method.
Thanks...
10-17-2022 07:57 AM
@T. wrote:
Hello,
This is how I would have imagined it. Unfortunately, an error always comes out of the CreateInstance method.
Could you try removing ", mscorlib" from the type string?
10-17-2022 08:04 AM
@T. wrote:This is how I would have imagined it. Unfortunately, an error always comes out of the CreateInstance method.
You also need to close the list and type references, or you'll leak memory.