<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:41:41 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[CSHARP-2130] Deserialization of polymorphic types throwing exception</title>
                <link>https://jira.mongodb.org/browse/CSHARP-2130</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;Am trying to deserialize polymorphic classes. The default deserialization works when document is created in the same function, but throws an exception when trying to deserialize else where. &lt;/p&gt;

&lt;p&gt;Here are SIX steps to reproduce:&lt;br/&gt;
1) Create a blank asp.net core 2 mvc webapi project. &lt;br/&gt;
2 Add necessary nuget&apos;s for Mongo Driver&lt;/p&gt;

&lt;p&gt;3) In start up, add this line:             BsonSerializer.RegisterDiscriminatorConvention(typeof(Base), new ScalarDiscriminatorConvention(&quot;_t&quot;));&lt;/p&gt;

&lt;p&gt;Default template contains values controller:&lt;/p&gt;

&lt;p&gt;4) Replace the file with below code:&lt;/p&gt;

&lt;p&gt;##################################################################################&lt;br/&gt;
using System;&lt;br/&gt;
using System.Collections.Generic;&lt;br/&gt;
using System.Linq;&lt;br/&gt;
using System.Threading.Tasks;&lt;br/&gt;
using Microsoft.AspNetCore.Mvc;&lt;br/&gt;
using MongoDB.Driver;&lt;br/&gt;
using MongoDB.Bson.Serialization;&lt;br/&gt;
using MongoDB.Bson.Serialization.Conventions;&lt;br/&gt;
using MongoDB.Bson.Serialization.Attributes;&lt;br/&gt;
using MongoDB.Bson.Serialization.IdGenerators;&lt;br/&gt;
using MongoDB.Bson;&lt;/p&gt;

&lt;p&gt;namespace apitest.Controllers&lt;br/&gt;
{&lt;br/&gt;
    [Route(&quot;api/&lt;span class=&quot;error&quot;&gt;&amp;#91;controller&amp;#93;&lt;/span&gt;&quot;)]&lt;br/&gt;
    public class ValuesController : Controller&lt;br/&gt;
    {&lt;br/&gt;
        // GET api/values&lt;br/&gt;
        &lt;span class=&quot;error&quot;&gt;&amp;#91;HttpGet&amp;#93;&lt;/span&gt;&lt;br/&gt;
        public IActionResult Get()&lt;br/&gt;
        {&lt;br/&gt;
            List&amp;lt;Base&amp;gt; objs = new List&amp;lt;Base&amp;gt;();&lt;br/&gt;
            Base b = new Base2() &lt;/p&gt;
{ baseName = &quot;BaseName&quot;, IBaseName = &quot;IBaseName&quot;, base2Name = &quot;base2Name&quot; }
&lt;p&gt;;&lt;br/&gt;
            Base d = new Derived() &lt;/p&gt;
{ baseName = &quot;BaseName&quot;, IBaseName = &quot;IBaseName&quot;, derivedName = &quot;derivedName&quot; }
&lt;p&gt;;&lt;br/&gt;
            objs.Add(b);&lt;br/&gt;
            objs.Add(d);&lt;/p&gt;

&lt;p&gt;            MongoDbContext m = new MongoDbContext();&lt;br/&gt;
            var testCollection = m.GetCollection&amp;lt;Base&amp;gt;(&quot;test&quot;);&lt;/p&gt;

&lt;p&gt;            testCollection.DeleteMany(_ =&amp;gt; true);&lt;/p&gt;

&lt;p&gt;            foreach (var obj in objs)&lt;/p&gt;
            {
                testCollection.InsertOne(obj);
                Console.WriteLine($&quot;Completed write&quot;);
            }

&lt;p&gt;            var filterDefinition = Builders&amp;lt;Base&amp;gt;.Filter.Where(s =&amp;gt; true);&lt;br/&gt;
            IEnumerable&amp;lt;Base&amp;gt; list = testCollection.Find(filterDefinition).ToList();&lt;/p&gt;

&lt;p&gt;            foreach (var o in list)&lt;br/&gt;
            {&lt;br/&gt;
                Console.WriteLine($&quot;&lt;/p&gt;
{o.GetType().Name}
&lt;p&gt;&quot;);&lt;br/&gt;
            }&lt;br/&gt;
            Console.ReadLine();&lt;br/&gt;
            return new OkResult();&lt;br/&gt;
        }&lt;br/&gt;
    }&lt;/p&gt;

&lt;p&gt;    public abstract class Base &lt;br/&gt;
    {&lt;br/&gt;
        &lt;span class=&quot;error&quot;&gt;&amp;#91;BsonIgnoreIfDefault&amp;#93;&lt;/span&gt;&lt;br/&gt;
        &lt;span class=&quot;error&quot;&gt;&amp;#91;BsonId&amp;#93;&lt;/span&gt;&lt;br/&gt;
        &lt;span class=&quot;error&quot;&gt;&amp;#91;BsonRepresentation(BsonType.ObjectId)&amp;#93;&lt;/span&gt;&lt;br/&gt;
        public string Id;&lt;br/&gt;
        public string baseName;&lt;br/&gt;
        public string IBaseName &lt;/p&gt;
{ get; set; }
&lt;p&gt;    }&lt;/p&gt;

&lt;p&gt;    public class Base2 : Base &lt;/p&gt;
{ public string base2Name; }
&lt;p&gt;    public class Derived : Base &lt;/p&gt;
{ public string derivedName; }

&lt;p&gt;    public class MongoDbContext&lt;br/&gt;
    {&lt;br/&gt;
        private IMongoDatabase _db;&lt;br/&gt;
        public MongoDbContext()&lt;/p&gt;
        {
            var client = new MongoClient(&quot;mongodb://localhost:27017&quot;);
            _db = client.GetDatabase(&quot;test&quot;);
        }
&lt;p&gt;        public IMongoCollection&amp;lt;T&amp;gt; GetCollection&amp;lt;T&amp;gt;(string collectionName)&lt;/p&gt;
        {
            return _db.GetCollection&amp;lt;T&amp;gt;(collectionName);
        }
&lt;p&gt;    }&lt;/p&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;##################################################################################&lt;/p&gt;

&lt;p&gt;Note that console properly shows the derived classes deserialized. &lt;/p&gt;

&lt;p&gt;5) Now, comment the following lines in the Get Method:&lt;br/&gt;
##################################################################################&lt;br/&gt;
            //testCollection.DeleteMany(_ =&amp;gt; true);&lt;/p&gt;

&lt;p&gt;            //foreach (var obj in objs)&lt;br/&gt;
            //&lt;/p&gt;
{
            //    testCollection.InsertOne(obj);
            //    Console.WriteLine($&quot;Completed write&quot;);
            //}
&lt;p&gt;##################################################################################&lt;/p&gt;

&lt;p&gt;6) Run again and see that it throws following exception.&lt;br/&gt;
##################################################################################&lt;br/&gt;
Application started. Press Ctrl+C to shut down.&lt;br/&gt;
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware&lt;span class=&quot;error&quot;&gt;&amp;#91;0&amp;#93;&lt;/span&gt;&lt;br/&gt;
      An unhandled exception has occurred while executing the request&lt;br/&gt;
System.InvalidOperationException: Can&apos;t compile a NewExpression with a constructor declared on an abstract class&lt;br/&gt;
   at System.Linq.Expressions.Compiler.LambdaCompiler.EmitNewExpression(Expression expr)&lt;br/&gt;
   at System.Linq.Expressions.Compiler.LambdaCompiler.EmitExpression(Expression node, CompilationFlags flags)&lt;br/&gt;
   at System.Linq.Expressions.Compiler.LambdaCompiler.EmitLambdaBody(CompilerScope parent, Boolean inlined, CompilationFlags flags)&lt;br/&gt;
   at System.Linq.Expressions.Compiler.LambdaCompiler.EmitLambdaBody()&lt;br/&gt;
   at System.Linq.Expressions.Compiler.LambdaCompiler.Compile(LambdaExpression lambda)&lt;br/&gt;
   at System.Linq.Expressions.Expression`1.Compile(Boolean preferInterpretation)&lt;br/&gt;
   at MongoDB.Bson.Serialization.BsonClassMap.GetCreator()&lt;br/&gt;
   at MongoDB.Bson.Serialization.BsonClassMap.CreateInstance()&lt;br/&gt;
   at MongoDB.Bson.Serialization.BsonClassMapSerializer`1.DeserializeClass(BsonDeserializationContext context)&lt;br/&gt;
   at MongoDB.Bson.Serialization.BsonClassMapSerializer`1.Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)&lt;br/&gt;
   at MongoDB.Bson.Serialization.IBsonSerializerExtensions.Deserialize&lt;span class=&quot;error&quot;&gt;&amp;#91;TValue&amp;#93;&lt;/span&gt;(IBsonSerializer`1 serializer, BsonDeserializationContext context)&lt;br/&gt;
   at MongoDB.Driver.Core.Operations.CursorBatchDeserializationHelper.DeserializeBatch&lt;span class=&quot;error&quot;&gt;&amp;#91;TDocument&amp;#93;&lt;/span&gt;(RawBsonArray batch, IBsonSerializer`1 documentSerializer, MessageEncoderSettings messageEncoderSettings)&lt;br/&gt;
   at MongoDB.Driver.Core.Operations.FindCommandOperation`1.CreateCursorBatch(BsonDocument commandResult)&lt;br/&gt;
   at MongoDB.Driver.Core.Operations.FindCommandOperation`1.CreateCursor(IChannelSourceHandle channelSource, BsonDocument commandResult, Boolean slaveOk)&lt;br/&gt;
   at MongoDB.Driver.Core.Operations.FindCommandOperation`1.Execute(IReadBinding binding, CancellationToken cancellationToken)&lt;br/&gt;
   at MongoDB.Driver.Core.Operations.FindOperation`1.Execute(IReadBinding binding, CancellationToken cancellationToken)&lt;br/&gt;
   at MongoDB.Driver.OperationExecutor.ExecuteReadOperation&lt;span class=&quot;error&quot;&gt;&amp;#91;TResult&amp;#93;&lt;/span&gt;(IReadBinding binding, IReadOperation`1 operation, CancellationToken cancellationToken)&lt;br/&gt;
   at MongoDB.Driver.MongoCollectionImpl`1.ExecuteReadOperation&lt;span class=&quot;error&quot;&gt;&amp;#91;TResult&amp;#93;&lt;/span&gt;(IReadOperation`1 operation, ReadPreference readPreference, CancellationToken cancellationToken)&lt;br/&gt;
   at MongoDB.Driver.MongoCollectionImpl`1.ExecuteReadOperation&lt;span class=&quot;error&quot;&gt;&amp;#91;TResult&amp;#93;&lt;/span&gt;(IReadOperation`1 operation, CancellationToken cancellationToken)&lt;br/&gt;
   at MongoDB.Driver.MongoCollectionImpl`1.FindSync&lt;span class=&quot;error&quot;&gt;&amp;#91;TProjection&amp;#93;&lt;/span&gt;(FilterDefinition`1 filter, FindOptions`2 options, CancellationToken cancellationToken)&lt;br/&gt;
   at MongoDB.Driver.FindFluent`2.ToCursor(CancellationToken cancellationToken)&lt;br/&gt;
   at MongoDB.Driver.IAsyncCursorSourceExtensions.ToList&lt;span class=&quot;error&quot;&gt;&amp;#91;TDocument&amp;#93;&lt;/span&gt;(IAsyncCursorSource`1 source, CancellationToken cancellationToken)&lt;br/&gt;
   at apitest.Controllers.ValuesController.Get() in C:\ws\gh\temp\apitest\apitest\Controllers\ValuesController.cs:line 40&lt;br/&gt;
   at lambda_method(Closure , Object , Object[] )&lt;br/&gt;
   at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)&lt;br/&gt;
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.&amp;lt;InvokeActionMethodAsync&amp;gt;d__12.MoveNext()&lt;br/&gt;
&amp;#8212; End of stack trace from previous location where exception was thrown &amp;#8212;&lt;br/&gt;
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()&lt;br/&gt;
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)&lt;br/&gt;
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.&amp;lt;InvokeNextActionFilterAsync&amp;gt;d__10.MoveNext()&lt;br/&gt;
&amp;#8212; End of stack trace from previous location where exception was thrown &amp;#8212;&lt;br/&gt;
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()&lt;br/&gt;
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)&lt;br/&gt;
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State&amp;amp; next, Scope&amp;amp; scope, Object&amp;amp; state, Boolean&amp;amp; isCompleted)&lt;br/&gt;
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.&amp;lt;InvokeInnerFilterAsync&amp;gt;d__14.MoveNext()&lt;br/&gt;
&amp;#8212; End of stack trace from previous location where exception was thrown &amp;#8212;&lt;br/&gt;
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()&lt;br/&gt;
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)&lt;br/&gt;
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.&amp;lt;InvokeNextResourceFilter&amp;gt;d__22.MoveNext()&lt;br/&gt;
&amp;#8212; End of stack trace from previous location where exception was thrown &amp;#8212;&lt;br/&gt;
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()&lt;br/&gt;
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)&lt;br/&gt;
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State&amp;amp; next, Scope&amp;amp; scope, Object&amp;amp; state, Boolean&amp;amp; isCompleted)&lt;br/&gt;
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.&amp;lt;InvokeFilterPipelineAsync&amp;gt;d__17.MoveNext()&lt;br/&gt;
&amp;#8212; End of stack trace from previous location where exception was thrown &amp;#8212;&lt;br/&gt;
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()&lt;br/&gt;
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)&lt;br/&gt;
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.&amp;lt;InvokeAsync&amp;gt;d__15.MoveNext()&lt;br/&gt;
&amp;#8212; End of stack trace from previous location where exception was thrown &amp;#8212;&lt;br/&gt;
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()&lt;br/&gt;
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)&lt;br/&gt;
   at Microsoft.AspNetCore.Builder.RouterMiddleware.&amp;lt;Invoke&amp;gt;d__4.MoveNext()&lt;br/&gt;
&amp;#8212; End of stack trace from previous location where exception was thrown &amp;#8212;&lt;br/&gt;
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()&lt;br/&gt;
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)&lt;br/&gt;
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.&amp;lt;Invoke&amp;gt;d__7.MoveNext()&lt;br/&gt;
##################################################################################&lt;/p&gt;
</description>
                <environment>Windows 10</environment>
        <key id="474067">CSHARP-2130</key>
            <summary>Deserialization of polymorphic types throwing exception</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="13202">Works as Designed</resolution>
                                        <assignee username="wan.bachtiar@mongodb.com">Wan Bachtiar</assignee>
                                    <reporter username="kiranj">kiranj email</reporter>
                        <labels>
                            <label>core</label>
                    </labels>
                <created>Tue, 19 Dec 2017 00:33:24 +0000</created>
                <updated>Fri, 27 Oct 2023 13:25:04 +0000</updated>
                            <resolved>Mon, 25 Feb 2019 20:43:18 +0000</resolved>
                                    <version>2.4.4</version>
                                                    <component>Serialization</component>
                                        <votes>0</votes>
                                    <watches>4</watches>
                                                                                                                <comments>
                            <comment id="2159352" author="wan.bachtiar" created="Fri, 22 Feb 2019 02:34:16 +0000"  >&lt;blockquote&gt;&lt;p&gt;System.InvalidOperationException: Can&apos;t compile a NewExpression with a constructor declared on an abstract class&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;Hi Kiranj, &lt;/p&gt;

&lt;p&gt;The exception is thrown by &lt;tt&gt;LambdaCompiler.EmitNewExpression&lt;/tt&gt; because it&apos;s trying to construct from an abstract class. When deserializing polymorphic classes, it is important that the serializer know about all the classes in the hierarchy before deserialization begins. You could either declare:&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    [BsonKnownTypes(&lt;/span&gt;&lt;span style=&quot;color: #006699; font-weight: bold; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;typeof&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;(Base2), &lt;/span&gt;&lt;span style=&quot;color: #006699; font-weight: bold; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;typeof&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;(Derived))]&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #006699; font-weight: bold; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #006699; font-weight: bold; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;abstract&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #006699; font-weight: bold; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; Base &lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    {&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;        [BsonIgnoreIfDefault]&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;        [BsonId]&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;        [BsonRepresentation(BsonType.ObjectId)]&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #006699; font-weight: bold; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #006699; font-weight: bold; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; Id;&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #006699; font-weight: bold; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #006699; font-weight: bold; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; baseName;&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #006699; font-weight: bold; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #006699; font-weight: bold; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; IBaseName { &lt;/span&gt;&lt;span style=&quot;color: #006699; font-weight: bold; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color: #006699; font-weight: bold; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;set&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;; }&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    }&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;or, you could register individually via code: &lt;/p&gt;


&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    BsonClassMap.RegisterClassMap&amp;lt;Base&amp;gt;();&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    BsonClassMap.RegisterClassMap&amp;lt;Base2&amp;gt;();&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    BsonClassMap.RegisterClassMap&amp;lt;Derived&amp;gt;();&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;See also &lt;a href=&quot;http://mongodb.github.io/mongo-csharp-driver/2.7/reference/bson/mapping/polymorphism/#polymorphism&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;MongoDB .NET/C# driver: Polymorphism&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Please note that the CSHARP project is for reporting bugs or feature suggestions for the MongoDB .NET/C# driver. If you have any follow-up questions on the use of the driver, please post a question on &lt;a href=&quot;https://groups.google.com/forum/#!forum/mongodb-user&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;mongodb-user&lt;/a&gt; group with relevant the information.&lt;/p&gt;

&lt;p&gt;Regards, &lt;br/&gt;
Wan. &lt;/p&gt;</comment>
                            <comment id="1951111" author="n.grudinin" created="Thu, 19 Jul 2018 14:06:21 +0000"  >&lt;p&gt;try to use &lt;span class=&quot;error&quot;&gt;&amp;#91;KnownBsonTypes&amp;#93;&lt;/span&gt; attribute on base class&lt;/p&gt;</comment>
                            <comment id="1755249" author="kiranj" created="Tue, 19 Dec 2017 00:34:33 +0000"  >&lt;p&gt;Before step 5, build and run to see it working.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                            <outwardlinks description="duplicates">
                                                        </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hte40v:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>9223372036854775807</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>