irmen / Pyrolite

Java and .NET client interface for Pyro5 protocol
MIT License
177 stars 47 forks source link

Unable to use pickle serializer: System.InvalidCastException #70

Closed hoeche closed 5 years ago

hoeche commented 5 years ago

By using the pickle serializer I get following exception when doing:

Config.SERIALIZER = Config.SerializerType.pickle;
NameServerProxy ns = NameServerProxy.locateNS(null)
System.InvalidCastException: 'Unable to cast object of type 'System.Collections.Hashtable' to type 'System.Collections.Generic.IDictionary`2[System.Object,System.Object]'.'

StackTrace:
   at Razorvine.Pyro.PyroProxy._handshake()
   at Razorvine.Pyro.PyroProxy.connect()
   at Razorvine.Pyro.PyroProxy.internal_call(String method, String actual_objectId, UInt16 flags, Boolean checkMethodName, Object[] parameters)
   at Razorvine.Pyro.NameServerProxy.locateNS(String host, Int32 port, Byte[] hmacKey)
   at Razorvine.Pyro.NameServerProxy.locateNS(String host, Int32 port, Byte[] hmacKey)

When using the serpent serializer it works fine. I digged into the code and it seems C# has problems casting Hashtable to IDictionary<object, object>. When I create a Dictionary<object, object> and copy all elements from the Hashtable into the dictionary, then it also works with pickle.

irmen commented 5 years ago

I've pused a fix in ed875ce521712a3c9cb0f8002612c033afec7284

Can you verify if this works as intended for you as well? If so, I'll put out a new 4.31 release.

For reference, I can now run the program below without errors, where it crashed before this fix:

using System;
using Razorvine.Pyro;

namespace TestDotnetPyrolitePickle
{
    class Program
    {
        static void Main(string[] args)
        {
            Config.SERIALIZER = Config.SerializerType.pickle;
            var ns = NameServerProxy.locateNS(null, 0);
            Console.WriteLine(ns);
            foreach (var (objectname, uri) in ns.list(null, null))
            {
                Console.WriteLine(objectname + " -> " +uri);
            }
            ns.close();
        }
    }
}
hoeche commented 5 years ago

It works perfect! I will do more intensive testing within the next weeks. Thank you very much!

irmen commented 5 years ago

Fantastic . I'll release a new version shortly.

Be advised that using the pickle serializer is better avoided. (security issues, and support for it is gone in the next Pyro version Pyro5)

irmen commented 5 years ago

4.31 pushed to nuget.org