C# / IronPython Interop and the "float" data type
Posted
by Adam Haile
on Stack Overflow
See other posts from Stack Overflow
or by Adam Haile
Published on 2010-06-09T13:18:05Z
Indexed on
2010/06/09
13:22 UTC
Read the original article
Hit count: 213
Working on a project that uses some IronPython scripts to as plug-ins, that utilize functionality coded in C#. In one of my C# classes, I have a property that is of type:
Dictionary<int, float>
I set the value of that property from the IronPython code, like this:
mc = MyClass()
mc.ValueDictionary = Dictionary[int, float]({1:0.0, 2:0.012, 3:0.024})
However, when this bit of code is run, it throws the following exception:
Microsoft.Scripting.ArgumentTypeException was unhandled by user code
Message=expected Dictionary[int, Single], got Dictionary[int, float]
To make things weirder, originally the C# code used
Dictionary<int, double>
but I could not find a "double" type in IronPython, tried "float" on a whim and it worked fine, giving no errors. But now that it's using float on both ends (which it should have been using from the start) it errors, and thinks that the C# code is using the "Single" data type?!
I've even checked in the object browser for the C# library and, sure enough, it shows as using a "float" type and not "Single"
© Stack Overflow or respective owner