I wrote an IronPython package to do some data-crunching, and now I am wrapping it in a C# application. Part of the application's functionality is to save the state of a project, and then later to restore that saved state.
I am using the pickle module in IronPython to save an object of a class from my custom package. Before I did the wrapping in C#, that was no problem: I used the pickle.dump() function to serialize the object to a file. Now I want to use the pickle.dumps() function to serialize the object to a string, then pass that string to a C# object and serialize THAT object with an XmlSerializer.
Serialization seems to work, but deserialization breaks down: C# gets the deserialized string and passes it to IronPython, which should be able to reconstitute the original object with the pickle.loads() function, but instead raises this error:
System.Collections.Generic.KeyNotFoundException {"ô"}
Can you help me solve this problem? I have two theories:
Perhaps there is a difference in the string encodings between IronPython and C#, or between C#, IronPython, and what is expected by the
picklemodule?Not the entire string is being serialized in the first place, so I am just passing nonsense to
pickle.loads()
My evidence that leads me to these theories:
The missing key in the error message (ô) looks like a bit of unicode-parsed-as-ASCII-text.
If I break execution (in debug mode of Visual Studio 2010) and look at the string before it is passed to IronPython for unpicking, what I see is not long enough to represent the entire object. But it might just reach the limit of what the Visual Studio debugger will display.
Thanks in advance!