-
Type: Bug
-
Resolution: Works as Designed
-
Priority: Major - P3
-
None
-
Affects Version/s: 2.10.4
-
Component/s: Serialization
-
Labels:None
Currently if a DiscriminatorConvention is registered for object type, it is ignored.
Sample bug exposing code:
Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
BsonSerializer.RegisterDiscriminatorConvention(typeof(object), new MyDiscriminatorConvention("_t"));
In BsonSerializer.LookupDiscriminatorConvention(Type type) we can read:
Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
// inherit the discriminator convention from the closest parent (that isn't object) that has one // otherwise default to the standard hierarchical convention Type parentType = type.GetTypeInfo().BaseType; while (convention == null) { if (parentType == typeof(object)) { convention = StandardDiscriminatorConvention.Hierarchical; break; } if (__discriminatorConventions.TryGetValue(parentType, out convention)) { break; } parentType = parentType.GetTypeInfo().BaseType; }
This is evidently a bug, also because before on the code we can read a passage where a default DiscriminatorConvention is assigned for object type, so it is not intended to be ignored:
Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
if (type == typeof(object)) { // if there is no convention registered for object register the default one convention = new ObjectDiscriminatorConvention("_t"); RegisterDiscriminatorConvention(typeof(object), convention); }