orleans icon indicating copy to clipboard operation
orleans copied to clipboard

OrleansJsonSerializer deserialize Global namespace type incorrectly

Open bluexo opened this issue 5 years ago • 7 comments

Sometimes , when deserialize an Enum type , will got TypeAccessException , at this position , https://github.com/dotnet/orleans/blob/603e70a1c018454af53ed85669ff5b9c8cef1538/src/Orleans.Core/Serialization/SerializationManager.cs#L1745 because SerializationManager has not register the enum type correctly! https://github.com/dotnet/orleans/blob/603e70a1c018454af53ed85669ff5b9c8cef1538/src/Orleans.Core/Serialization/SerializationManager.cs#L1683 the serializationManager.types cannot found the Enum type!

I had created the test code , that will reproduced the problem. @ReubenBond https://github.com/dayezhao/orleans/blob/caa550946297f9cbf4546134839fe46ba4edffe2/test/NonSilo.Tests/Serialization/OrleansJsonSerializerTests.cs#L63

bluexo avatar Jan 06 '20 09:01 bluexo

I think the enum should be marked as [Serializable]

ReubenBond avatar Jan 06 '20 19:01 ReubenBond

Marked SerializableAttribute has no effect , I dont think enum type should be marked SerializableAttribute , it's not necessary

bluexo avatar Jan 07 '20 00:01 bluexo

If I register the type when serialize , that will be resolved this question https://github.com/dotnet/orleans/blob/603e70a1c018454af53ed85669ff5b9c8cef1538/src/Orleans.Core/Serialization/SerializationManager.cs#L862

            if (t.IsEnum)
            {
                writer.WriteTypeHeader(t, expected);
                WriteEnum(obj, writer, t);

                //Register Enum type when serialize can prevent 'TypeAccessException'
                if (!sm.types.ContainsKey(t.FullName))
                    sm.TryLookupExternalSerializer(t, out _);

                return;
            }

but when my silos on different process or machine , this question still exists , because the enum type maybe serialize on process/machine A , but deserialize on process/machine B .

bluexo avatar Jan 07 '20 11:01 bluexo

Is the enum in an assembly which does not have code generation enabled?

ReubenBond avatar Jan 07 '20 17:01 ReubenBond

I think I had pinpointed the problem.

If a custom type in global namespace , the code generator cannot generate corresponding code , but if the type is not enum type , that can serialize by ExternalSerializer (e.g OrleansJsonSerializer ) and register to SerializationManager .
when silos on different process or machine , this question still exists , because the type maybe serialize on process/machine A , but deserialize on process/machine B .

So all global namespace type cannot deserialize correctly!

I had created the test project , it's base on Orleans HelloWorld example project . HelloWorld

namespace HelloWorld
{
    public enum SampleEnum  {   One  }
}

public enum GlobalEnum {  One }

var g = _client.GetGrain<IHelloArchive>(0);

SampleEnum sampleEnum = await g.GetEnum();
Console.WriteLine(":) The SampleEnum type in a named namespace , So it's no problem!");

GlobalEnum globalEnum = await g.GetGlobalEnum();
Console.WriteLine(":( The GlobalEnum type will occurs [[[[ TypeAccessException ]]]]");

bluexo avatar Jan 08 '20 07:01 bluexo

@ReubenBond Any plan fix the issues ?

bluexo avatar Jan 12 '20 02:01 bluexo

We've moved this issue to the Backlog. This means that it is not going to be worked on for the coming release. We review items in the backlog at the end of each milestone/release and depending on the team's priority we may reconsider this issue for the following milestone.

ghost avatar Jul 28 '22 23:07 ghost