<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:48:50 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-4634] Error in LINQ3 provider when custom ObjectSerializer is used</title>
                <link>https://jira.mongodb.org/browse/CSHARP-4634</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;h4&gt;&lt;a name=&quot;Summary&quot;&gt;&lt;/a&gt;Summary&lt;/h4&gt;

&lt;p&gt;version 2.19 of C# Driver.&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;&lt;em&gt;With new LINQ3 provider, if you use a custom ObjectSerializer like Elsa does (&lt;a href=&quot;https://github.com/elsa-workflows/elsa-core/blob/047c51d7cf7b8a3230353e3518439704756ca95b/src/persistence/Elsa.Persistence.MongoDb/Serializers/ObjectSerializer.cs)&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/elsa-workflows/elsa-core/blob/047c51d7cf7b8a3230353e3518439704756ca95b/src/persistence/Elsa.Persistence.MongoDb/Serializers/ObjectSerializer.cs)&lt;/a&gt; you incurr in an error when you execute any LINQ query based on new LINQ3 provider&lt;/em&gt;&lt;/tt&gt;&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;&#160;&lt;em&gt;---&amp;gt; System.InvalidCastException: Unable to cast object of type &apos;Elsa.Persistence.MongoDb.Serializers.ElsaObjectSerializer&apos; to type &apos;MongoDB.Bson.Serialization.Serializers.ObjectSerializer&apos;.&lt;/em&gt;&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160;&lt;em&gt;at MongoDB.Bson.Serialization.Serializers.DiscriminatedInterfaceSerializer`1..ctor(IDiscriminatorConvention discriminatorConvention, IBsonSerializer`1 interfaceSerializer)&lt;/em&gt;&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160;&lt;em&gt;at MongoDB.Bson.Serialization.Serializers.DiscriminatedInterfaceSerializer`1..ctor(IDiscriminatorConvention discriminatorConvention)&lt;/em&gt;&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160;&lt;em&gt;at MongoDB.Bson.Serialization.Serializers.DiscriminatedInterfaceSerializer`1..ctor()&lt;/em&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;h4&gt;&lt;a name=&quot;HowtoReproduce&quot;&gt;&lt;/a&gt;How to Reproduce&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;It is sufficient to declare a custom object serializer, like elsa does &lt;tt&gt;&lt;/em&gt;(&lt;a href=&quot;https://github.com/elsa-workflows/elsa-core/blob/047c51d7cf7b8a3230353e3518439704756ca95b/src/persistence/Elsa.Persistence.MongoDb/Serializers/ObjectSerializer.cs)&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/elsa-workflows/elsa-core/blob/047c51d7cf7b8a3230353e3518439704756ca95b/src/persistence/Elsa.Persistence.MongoDb/Serializers/ObjectSerializer.cs)&lt;/a&gt;&lt;em&gt;&lt;/tt&gt; register the serializer, persists some objects and then issue a LINQ query to retrieve. If you look at the attached image, in the constructor of &#160;DiscriminatedInterfaceSerializer class, the driver is looking for MongoDb serializer for object but it CAST immeditaly to ObjectSerializer, thus preventing anyone from registering own serializer for object class.&lt;/em&gt;&lt;/p&gt;
&lt;h4&gt;&lt;a name=&quot;AdditionalBackground&quot;&gt;&lt;/a&gt;Additional Background&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Look at attached image.&lt;/em&gt;&lt;/p&gt;</description>
                <environment></environment>
        <key id="2331950">CSHARP-4634</key>
            <summary>Error in LINQ3 provider when custom ObjectSerializer is used</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="10300" iconUrl="https://jira.mongodb.org/images/icons/priorities/medium.svg">Unknown</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="13201">Fixed</resolution>
                                        <assignee username="oleksandr.poliakov@mongodb.com">Oleksandr Poliakov</assignee>
                                    <reporter username="alkampfer@nablasoft.com">Gian Maria Ricci</reporter>
                        <labels>
                    </labels>
                <created>Thu, 4 May 2023 13:56:37 +0000</created>
                <updated>Sat, 28 Oct 2023 11:46:53 +0000</updated>
                            <resolved>Tue, 23 May 2023 18:29:09 +0000</resolved>
                                                    <fixVersion>2.19.2</fixVersion>
                                                        <votes>0</votes>
                                    <watches>3</watches>
                                                                                                                <comments>
                            <comment id="5450268" author="xgen-internal-githook" created="Wed, 24 May 2023 21:23:47 +0000"  >&lt;p&gt;Author: &lt;/p&gt;
{&apos;name&apos;: &apos;Oleksandr Poliakov&apos;, &apos;email&apos;: &apos;31327136+sanych-sun@users.noreply.github.com&apos;, &apos;username&apos;: &apos;sanych-sun&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-4634&quot; title=&quot;Error in LINQ3 provider when custom ObjectSerializer is used&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-4634&quot;&gt;&lt;del&gt;CSHARP-4634&lt;/del&gt;&lt;/a&gt;: Error in LINQ3 provider when custom ObjectSerializer is used (#1080)&lt;br/&gt;
Branch: v2.19.x&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/commit/513d0ce685354b183779cc49e02243daba4f136c&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/commit/513d0ce685354b183779cc49e02243daba4f136c&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="5446312" author="xgen-internal-githook" created="Tue, 23 May 2023 18:28:42 +0000"  >&lt;p&gt;Author: &lt;/p&gt;
{&apos;name&apos;: &apos;Oleksandr Poliakov&apos;, &apos;email&apos;: &apos;31327136+sanych-sun@users.noreply.github.com&apos;, &apos;username&apos;: &apos;sanych-sun&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-4634&quot; title=&quot;Error in LINQ3 provider when custom ObjectSerializer is used&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-4634&quot;&gt;&lt;del&gt;CSHARP-4634&lt;/del&gt;&lt;/a&gt;: Error in LINQ3 provider when custom ObjectSerializer is used (#1080)&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/commit/43f99178442c2f3cacd2738142de18b540de7afd&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/commit/43f99178442c2f3cacd2738142de18b540de7afd&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="5415159" author="JIRAUSER1273473" created="Wed, 10 May 2023 16:42:46 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=alkampfer%40nablasoft.com&quot; class=&quot;user-hover&quot; rel=&quot;alkampfer@nablasoft.com&quot;&gt;alkampfer@nablasoft.com&lt;/a&gt; .&lt;/p&gt;

&lt;p&gt;Thank you for the provided code, it helped a lot! So here is the minimal code to reproduce the problem:&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;var collection = db.GetCollection&amp;lt;WorkflowDefinition&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;WorkflowDefinition&quot;&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;   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;var result = collection.AsQueryable()&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;    .Where(w =&amp;gt; ((ITenantScope)w).TenantId == &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;abc&quot;&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;    .Count(); &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;Cast to an interface somehow causes the problem. This is definitely a bug in LINQ provider. I will continue investigating the problem and keep you posted.&lt;/p&gt;</comment>
                            <comment id="5414106" author="JIRAUSER1269368" created="Wed, 10 May 2023 12:47:09 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=oleksandr.poliakov%40mongodb.com&quot; class=&quot;user-hover&quot; rel=&quot;oleksandr.poliakov@mongodb.com&quot;&gt;oleksandr.poliakov@mongodb.com&lt;/a&gt;&#160;&lt;/p&gt;

&lt;p&gt;actually I struggled to reproduce in a simple project, it seems that is triggered by some special condition that happens inside elsa.workflow, but you have a repro here &lt;a href=&quot;https://github.com/alkampfergit/MongoDbNewDriverTest/tree/master/2.19&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/alkampfergit/MongoDbNewDriverTest/tree/master/2.19&lt;/a&gt; in that folder you can find a project that generates the bug using the LINQ3 provider and works perfectly with LINQ2 provider. It uses Elsa.Workflow internal classes but it is a really simple repro that you can run.&lt;/p&gt;

&lt;p&gt;You do not need to have test data in database, it raises exception even is the collection does not exists / is empty, just run the sample and you will get the exception.&lt;/p&gt;

&lt;p&gt;The error is inside class DiscriminatedInterfaceSerializer line 84, where the mongodb-csharp-driver performs a LookupSerializer but instead of casting to the interface will cast into internal specific implementation. I was able to reproduce using only elsa original class, but with the repro it is possible to investigate the problem.&lt;/p&gt;

&lt;p&gt;&lt;span class=&quot;image-wrap&quot; style=&quot;&quot;&gt;&lt;img src=&quot;https://jira.mongodb.org/secure/attachment/449051/449051_image-2023-05-10-14-44-32-999.png&quot; style=&quot;border: 0px solid black&quot; /&gt;&lt;/span&gt;&lt;/p&gt;</comment>
                            <comment id="5413019" author="JIRAUSER1273473" created="Tue, 9 May 2023 21:33:25 +0000"  >&lt;p&gt;Hey &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=alkampfer%40nablasoft.com&quot; class=&quot;user-hover&quot; rel=&quot;alkampfer@nablasoft.com&quot;&gt;alkampfer@nablasoft.com&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Thanks for reporting this issue. We cannot reproduce the issue as per provided steps to reproduce, the exception suggests that some cast to an interface should be involved. Could you please provide a minimal reproducible example to help us debug it?&#160;&lt;/p&gt;

&lt;p&gt;Thanks&lt;/p&gt;</comment>
                            <comment id="5400641" author="JIRAUSER1263145" created="Thu, 4 May 2023 13:56:41 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=alkampfer%40nablasoft.com&quot; class=&quot;user-hover&quot; rel=&quot;alkampfer@nablasoft.com&quot;&gt;alkampfer@nablasoft.com&lt;/a&gt;, thank you for reporting this issue! The team will look into it and get back to you soon. &lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                            <attachment id="447956" name="2023-05-04_15-55-02.png" size="158764" author="alkampfer@nablasoft.com" created="Thu, 4 May 2023 13:55:34 +0000"/>
                            <attachment id="449051" name="image-2023-05-10-14-44-32-999.png" size="101636" author="alkampfer@nablasoft.com" created="Wed, 10 May 2023 12:44:31 +0000"/>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                        <customfield id="customfield_10011" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Backwards Compatibility</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10038"><![CDATA[Fully Compatible]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10257" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Documentation Changes</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="11861"><![CDATA[Not Needed]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_14266" key="com.atlassian.jira.plugin.system.customfieldtypes:textarea">
                        <customfieldname>Documentation Changes Summary</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>&lt;p&gt;1.  What would you like to communicate to the user about this feature?&lt;br/&gt;
2.  Would you like the user to see examples of the syntax and/or executable code and its output?&lt;br/&gt;
3.  Which versions of the driver/connector does this apply to?&lt;/p&gt;</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|i1pyl4:</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>