orleans
orleans copied to clipboard
OrleansJsonSerializer deserialize Global namespace type incorrectly
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
I think the enum should be marked as [Serializable]
Marked SerializableAttribute has no effect , I dont think enum type should be marked SerializableAttribute , it's not necessary
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 .
Is the enum in an assembly which does not have code generation enabled?
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 ]]]]");
@ReubenBond Any plan fix the issues ?
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.