-
Notifications
You must be signed in to change notification settings - Fork 1.3k
CSHARP-4634: Error in LINQ3 provider when custom ObjectSerializer is used #1080
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
throw new BsonSerializationException("Can't set discriminator convention on custom object serializer."); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to also change the no-argument constructor to:
public DiscriminatedInterfaceSerializer()
: this(discriminatorConvention: null)
{
}
and postpone the lookup of the DiscriminatorConvention until later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -81,7 +81,19 @@ public DiscriminatedInterfaceSerializer(IDiscriminatorConvention discriminatorCo | |||
|
|||
_interfaceType = typeof(TInterface); | |||
_discriminatorConvention = discriminatorConvention; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_discriminatorConvention = discriminatorConvention ?? BsonSerializer.LookupDiscriminatorConvention(typeof(TInterface));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
_objectSerializer = BsonSerializer.LookupSerializer<object>(); | ||
if (_objectSerializer is ObjectSerializer standardObjectSerializer) | ||
{ | ||
_objectSerializer = standardObjectSerializer.WithDiscriminatorConvention(discriminatorConvention); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably need to pass _discriminatorConvention
instead of discriminatorConvention
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was one extra semicolon (harmless). You might want to remove it.
Don't forget to remove the test because it registers a custom object serializer.
LGTM
@@ -80,8 +80,20 @@ public DiscriminatedInterfaceSerializer(IDiscriminatorConvention discriminatorCo | |||
} | |||
|
|||
_interfaceType = typeof(TInterface); | |||
_discriminatorConvention = discriminatorConvention; | |||
_objectSerializer = ((ObjectSerializer)BsonSerializer.LookupSerializer<object>()).WithDiscriminatorConvention(_discriminatorConvention); | |||
_discriminatorConvention = discriminatorConvention ?? BsonSerializer.LookupDiscriminatorConvention(typeof(TInterface));; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra semicolon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ups, removed. Thanks!
No description provided.