Closed aienabled closed 7 years ago
@aienabled nullable casted to object IS actually null reference, this is C# nullable boxing rules. Plain null object serialization is not supported. For reference types you also can't do Serialize(stream, null, typeof(XXX))
and this is the same case.
You can use your custom wrapper which won't use these boxing rules (instead of Nullable<T>
use YourNullable<T>
).
@AqlsSolutions, thanks, I absolutely forgot about this.
Wrapped into this structure and it works perfectly well now:
[SerializableType]
public struct SerializationContainer<TValue> : ISerializationContainer
{
[SerializableMember(1, format: ValueFormat.NotSpecified)]
public TValue Value;
public SerializationContainer(TValue value)
{
this.Value = value;
}
public object GetAbstractValue()
{
return this.Value;
}
}
public interface ISerializationContainer
{
object GetAbstractValue();
}
Hello!
I've noticed than when we serialize nullable enum value with null value and casted to object we have a NullReferenceException. I mean something like:
Could you check this please?