You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Library name and version
Microsoft.Orleans.Serialization 9.0.1, 7.2.6 (and maybe other versions).
Bug description
We noticed that the Orleans serializer is unable to serialize correctly private fields of classes that are defined in an assembly with a single to Orleans (Microsoft.Orleans.Serialization.Abstractions NuGet package).
Here is an example of a class that cannot be handled by the serializer:
Reproduction Steps This repository is containing the following unit test that can be used to reproduce the bug:
[TestCaseSource(nameof(GetObjectsToCheck))]publicvoidShouldSerializeAndDeserializeObject<T>(T@object){// Arrangevarserializer=cluster!.ServiceProvider.GetRequiredService<Serializer>();// ActvarbinaryData=serializer.SerializeToArray(@object);vardeserializedObject=serializer.Deserialize<T>(binaryData);// AssertdeserializedObject.Should().BeEquivalentTo(@object);}privatestaticIEnumerable<TestCaseData>GetObjectsToCheck(){yieldreturnnewTestCaseData(newPlane(brand:"Airbus",model:"A350"));// class with private fields defined in the test assembly (✅ passed)yieldreturnnewTestCaseData(newCar(brand:"Alpine",model:"A110"));// class with protected fields defined in another assembly (✅ passed)yieldreturnnewTestCaseData(newMotorBike(brand:"Honda",model:"CB1000R"));// class with private fields defined in another assembly (❌ failed)yieldreturnnewTestCaseData(newTrain(brand:"Alstom",model:"TGV M"));// class with public properties defined in another assembly (✅ passed)}
The test case with MotorBike object failed with the following error message:
ShouldSerializeAndDeserializeObject<MotorBike>(OrleansSerialization.Contracts.MotorBike)
Source: SerializationTests.cs line 25
Duration: 59 ms
Message:
Expected property deserializedObject.Brand to be "Honda", but found <null>.
Expected property deserializedObject.Model to be "CB1000R", but found <null>.
With configuration:
- Use declared types and members
- Compare enums by value
- Compare tuples by their properties
- Compare anonymous types by their properties
- Compare records by their members
- Include non-browsable members
- Match member by name (or throw)
- Be strict about the order of items in byte arrays
- Without automatic conversion.
Stack Trace:
LateBoundTestFramework.Throw(String message)
TestFrameworkProvider.Throw(String message)
CollectingAssertionStrategy.ThrowIfAny(IDictionary`2 context)
AssertionScope.Dispose()
EquivalencyValidator.AssertEquality(Comparands comparands, EquivalencyValidationContext context)
ObjectAssertions`2.BeEquivalentTo[TExpectation](TExpectation expectation, Func`2 config, String because, Object[] becauseArgs)
ObjectAssertions`2.BeEquivalentTo[TExpectation](TExpectation expectation, String because, Object[] becauseArgs)
SerializationTests.ShouldSerializeAndDeserializeObject[T](T object) line 36
Workaround
We are able to circumvent the problem by changing the visibility of fields in the class to protected. This is clearly not an ideal solution for us.
Could you please take a look ?
Regards,
Ahmed
The text was updated successfully, but these errors were encountered:
I think it might be similar to this: #8860
i came across that from #9092 when i was having similar issues with record types and private fields. i think you can force it to behave by adding the SDK reference
Library name and version
Microsoft.Orleans.Serialization 9.0.1, 7.2.6 (and maybe other versions).
Bug description
We noticed that the Orleans serializer is unable to serialize correctly private fields of classes that are defined in an assembly with a single to Orleans (
Microsoft.Orleans.Serialization.Abstractions
NuGet package).Here is an example of a class that cannot be handled by the serializer:
Reproduction Steps
This repository is containing the following unit test that can be used to reproduce the bug:
The test case with
MotorBike
object failed with the following error message:Workaround
We are able to circumvent the problem by changing the visibility of fields in the class to protected. This is clearly not an ideal solution for us.
Could you please take a look ?
Regards,
Ahmed
The text was updated successfully, but these errors were encountered: