Writing a method that takes a Dictionary argument in a Zerotouch node

I implemented a simple class with one method that takes a Dictionary argument as follows.

public class Program
{
    static public Dictionary<string, object> ReadDictionary(Dictionary<string, object> dictionary)
    {
        return dictionary;
    }
}

My problem is that, if I pass a dictionary with mixed values including a Point like in the screenshot below, I will receive a “Warning: Object must implement IConvertible”, and the output dictionary does not include the point. Indeed, when I debugged the code and put a breakpoint on the line “return dictionary”, I can see that the input dictionary only contains 2 elements with keys “foo” and “bar”. What is my mistake here?

@Aparajit_Pratap thoughts?

@Michael_Kirschner2 this is a known issue. I attempted a fix but not quite there yet: https://github.com/DynamoDS/Dynamo/pull/9023. Will return to it when I get the chance.

3 Likes

Thank you Aparajit and Michael. In the meantime I will separate the keys and values as follows.

static public Dictionary<string, object> ReadDictionary(List<string> keys, List<object> values)
{
    if(keys.Count != values.Count)
    {
        throw new Exception("Must have the same size");
    }
    Dictionary<string, object> dictionary = new Dictionary<string, object>();
    for(int i = 0; i < keys.Count; i++)
    {
        dictionary.Add(keys[i], values[i]);
    }
    return dictionary;
}

1 Like

Many thanks Erik, that worked.
For the record, the IDictionary class in your code comes from System.Collections, instead of System.Collections.Generic.