<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:45:26 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-3494] Discriminator conventions don&apos;t work properly with generic types</title>
                <link>https://jira.mongodb.org/browse/CSHARP-3494</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;The default discriminator conventions (ie. HierarchicalDiscriminatorConvention) don&apos;t work properly with generic types. Trying to find/insert documents with varying generic types will cause an exception &quot;Ambiguous discriminator &apos;Type`1&apos;.&quot;.&lt;/p&gt;

&lt;p&gt;The problem and solution is also explained in this stackoverflow post: &lt;a href=&quot;https://stackoverflow.com/questions/25891373/mongodb-c-sharp-driver-type-discriminators-with-generic-class-inheriting-from-no&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://stackoverflow.com/questions/25891373/mongodb-c-sharp-driver-type-discriminators-with-generic-class-inheriting-from-no&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The problem seems to be, that the default discriminator conventions use the type&apos;s &lt;b&gt;Name&lt;/b&gt; property instead of its &lt;b&gt;FullName&lt;/b&gt; or &lt;b&gt;AssemblyQualifiedName&lt;/b&gt; property.&lt;br/&gt;
For some reason, using &lt;b&gt;FullName&lt;/b&gt; will throw an exception: &quot;Unknown discriminator value ...&apos;, while &lt;b&gt;AssemblyQualifiedName&lt;/b&gt; works.&lt;/p&gt;

&lt;p&gt;This is also what causes this older issue: &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-1240&quot; class=&quot;external-link&quot; rel=&quot;nofollow&quot;&gt;https://jira.mongodb.org/browse/CSHARP-1240&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The fix for my application was creating a custom discriminator convention that inherits from &lt;b&gt;HierarchicalDiscriminatorConvention&lt;/b&gt; and return:&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;   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;classMap.ClassType.AssemblyQualifiedName&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;instead of:&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;   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;classMap.Discriminator&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;inside of the &lt;b&gt;GetDiscriminator&lt;/b&gt; method.&lt;br/&gt;
see: &lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/blob/v2.12.x/src/MongoDB.Bson/Serialization/Conventions/HierarchicalDiscriminatorConvention.cs&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/blob/v2.12.x/src/MongoDB.Bson/Serialization/Conventions/HierarchicalDiscriminatorConvention.cs&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;&lt;a name=&quot;Solution%2Fsuggestion%3A&quot;&gt;&lt;/a&gt;Solution/suggestion:&lt;/h4&gt;
&lt;p&gt;The problem seems to be, that inside of &lt;b&gt;BsonClassMap.cs&lt;/b&gt;, the &lt;b&gt;_discriminator&lt;/b&gt; field is assigned a wrong value:&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;   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;_discriminator = _classType.Name;&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: &lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/blob/v2.12.x/src/MongoDB.Bson/Serialization/BsonClassMap.cs#L973&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/blob/v2.12.x/src/MongoDB.Bson/Serialization/BsonClassMap.cs#L973&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Because of the usage of &lt;b&gt;_classType.Name&lt;/b&gt;, the discriminator conventions won&apos;t work for generic types.&lt;/p&gt;

&lt;p&gt;A quick fix could be to instead assign &lt;b&gt;AssemblyQualifiedName&lt;/b&gt;:&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;   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;_discriminator = _classType.AssemblyQualifiedName;&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;in turn, the default discriminator conventions that access&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;   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;classMap.Discriminator&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;will now receive the correct name.&lt;/p&gt;

&lt;p&gt;I&apos;m not sure why &lt;b&gt;FullName&lt;/b&gt; does not work, it should be investigated whether it is better to use it over &lt;b&gt;AssemblyQualifiedName&lt;/b&gt;.&lt;/p&gt;</description>
                <environment>TargetFramework: .NET 5&lt;br/&gt;
OS: Windows 10&lt;br/&gt;
MongoDB: Community Edition 4.4.3 2008R2Plus SLL (64 bit) - installed as Windows Service</environment>
        <key id="1654525">CSHARP-3494</key>
            <summary>Discriminator conventions don&apos;t work properly with generic types</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="10038" iconUrl="https://jira.mongodb.org/images/icons/subtask.gif" description="">Backlog</status>
                    <statusCategory id="2" key="new" colorName="default"/>
                                    <resolution id="-1">Unresolved</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="inuriasx@gmail.com">Raphael Rabl</reporter>
                        <labels>
                            <label>Serialization</label>
                            <label>generics</label>
                    </labels>
                <created>Fri, 19 Mar 2021 20:58:21 +0000</created>
                <updated>Fri, 20 Jan 2023 17:00:56 +0000</updated>
                                            <version>2.12.0</version>
                                                    <component>API</component>
                    <component>BSON</component>
                    <component>Serialization</component>
                                        <votes>0</votes>
                                    <watches>3</watches>
                                                                                                                <comments>
                            <comment id="3685151" author="james.kovacs" created="Fri, 26 Mar 2021 00:05:28 +0000"  >&lt;p&gt;Hi, Raphael,&lt;/p&gt;

&lt;p&gt;Thank you for reporting this issue. You are correct that it is related to &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-1240&quot; title=&quot;Type name store in the _t field missing generic type argument&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-1240&quot;&gt;&lt;del&gt;CSHARP-1240&lt;/del&gt;&lt;/a&gt;. The same concerns apply that although the current behaviour is problematic, however we fix it will result in a backward breaking change. We have scheduled an analysis of potential serialization improvements in an upcoming sprint and I have flagged this ticket to be part of that analysis. Thank you in advance for your patience and we will update this ticket when we decide on a path forward for this and related issues.&lt;/p&gt;

&lt;p&gt;Sincerely,&lt;br/&gt;
James&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10011">
                    <name>Depends</name>
                                                                <inwardlinks description="is depended on by">
                                        <issuelink>
            <issuekey id="1945077">CSHARP-3989</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                                                <inwardlinks description="is duplicated by">
                                        <issuelink>
            <issuekey id="195735">CSHARP-1240</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                            <issuelinktype id="10520">
                    <name>Problem/Incident</name>
                                            <outwardlinks description="causes">
                                        <issuelink>
            <issuekey id="195735">CSHARP-1240</issuekey>
        </issuelink>
                            </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_10857" key="com.pyxis.greenhopper.jira:gh-epic-link">
                        <customfieldname>Epic Link</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>CSHARP-3230</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hr48xi:oazi</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>