Error 91 From Variant to Data VI in LabVIEW

Updated Sep 6, 2023

Reported In

Software

  • LabVIEW

Issue Details

I'm getting the following error from the Variant to Data VI in LabVIEW:

Error 91 occurred at Variant To Data in <VI>
LabVIEW: (Hex 0x5B) The data type of the variant is not compatible with the data type wired to the type input.
 
error91.png

Solution

This error can be caused by different reasons, mainly an incorrect mapping between the input terminals of the Variant to Data VI, but it can also happen when using shared variables to store a variant with a map data type.
 

Converting the variant to an incorrect datatype

  • If you try to use the Variant to Data VI to extract a data type that is not included in the variant you are inputting, you can get this error. For instance, see the below VI, which is trying to extract a Boolean from a variant. 

 
While there is a Boolean in the variant, it is actually stored in the cluster, so you need to convert the variant to a cluster and then extract the Boolean from the cluster. The correct way to extract the Boolean from this code is shown below:

 
 
  • Do not wire the type output terminal of the Get Type Information VI to the type input terminal of the Variant to Data VI, to try to automatically detect the data type to convert the variant to, as this will most likely produce the 91 error. In this case the error can be produced as the type output terminal of the Get Type Information VI is an Enumerated data type. For example, the following code will produce the 91 error as LabVIEW will try to convert the Variant storing a Boolean into an Enumerated data type:
gettype.png


Using shared variables to store maps

If the original variant contains a map and you store it on a shared variable, when you pass the shared variable to the Variant to Data VI to try to extract the map from the variant, you will receive this error. This happens because shared variables currently can't store maps. Even though the shared variable can store a variant, at the end, the variant contains the original data, which in this case is a map. To work around this limitation, you can use different data structure (array or cluster) or separate out the keys and values of the map and rebuild the map after passing the data through the shared variables.

 

Additional Information

The type output terminal of the Get Type Information VI is an Enum value that contains items representing several data types in LabVIEW, but the wire carries an Enum value, not a value with the actual data type of the variant data in its input terminal.