<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:40:39 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-1773] Sample operator throws ArgumentException</title>
                <link>https://jira.mongodb.org/browse/CSHARP-1773</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&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;An unhandled exception of type &apos;System.ArgumentException&apos; occurred in System.Core.dll&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;&amp;nbsp;&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;Additional information: Expression of type &apos;System.Linq.IQueryable`1[T]&apos; cannot be used for parameter of type &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;  &apos;MongoDB.Driver.Linq.IMongoQueryable`1[T]&apos; of method &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;  &apos;MongoDB.Driver.Linq.IMongoQueryable`1[T] Sample[SubAgg]&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;  (MongoDB.Driver.Linq.IMongoQueryable`1[T], Int64)&apos;&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;This is coming from a relatively simple query: &lt;tt&gt;collection.AsQueryable().Where().OrderBy().Sample();&lt;/tt&gt;&lt;/p&gt;

&lt;p&gt;The reason for the exception is that&lt;/p&gt;

&lt;p&gt;1. tho the operations in MongoQueryable are defined as &lt;tt&gt;IMongoQueryable&amp;lt;T&amp;gt; Operation(this IMongoQueryable&amp;lt;T&amp;gt;,...)&lt;/tt&gt; &lt;br/&gt;
2. They call into the original LINQ implementation &lt;tt&gt;(IMongoQueryable&amp;lt;TResult&amp;gt;)Queryable.Operation(source, ...)&lt;/tt&gt;&lt;br/&gt;
3. Thus they return an Expression with the Type IQueryable&amp;lt;T&amp;gt; (&lt;tt&gt;source.Expression.Type&lt;/tt&gt;)&lt;/p&gt;

&lt;p&gt;Sample() creates the expression using &lt;tt&gt;Expression.Call&lt;/tt&gt;, but its method signature does not &quot;accept&quot; the expression (as per the validations inside Expression.Call).&lt;/p&gt;

&lt;p&gt;The solution is to change the method signature to&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;public static IMongoQueryable&amp;lt;TSource&amp;gt; Sample&amp;lt;TSource&amp;gt;(this IQueryable&amp;lt;TSource&amp;gt; source, long count)&lt;/tt&gt;&lt;/p&gt;

&lt;p&gt;Not sure if this solution is acceptable, but haven&apos;t found any better way (without reimplementing all LINQ operations so they have IMongoQueryable as their Expression.Type)&lt;/p&gt;

&lt;p&gt;I have a pull request &amp;amp; a simple unit test which I can submit if you want it&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/enyim/mongo-csharp-driver/commit/0910aa62b26a7c4460fa83ed03cb87e52a89c971&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/enyim/mongo-csharp-driver/commit/0910aa62b26a7c4460fa83ed03cb87e52a89c971&lt;/a&gt;&lt;/p&gt;</description>
                <environment></environment>
        <key id="320488">CSHARP-1773</key>
            <summary>Sample operator throws ArgumentException</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="9">Done</resolution>
                                        <assignee username="craig.wilson@mongodb.com">Craig Wilson</assignee>
                                    <reporter username="enyim">Attila Kisko</reporter>
                        <labels>
                    </labels>
                <created>Mon, 3 Oct 2016 15:03:18 +0000</created>
                <updated>Thu, 3 Nov 2016 13:51:35 +0000</updated>
                            <resolved>Thu, 3 Nov 2016 13:51:35 +0000</resolved>
                                    <version>2.3</version>
                                    <fixVersion>2.4</fixVersion>
                                    <component>Linq</component>
                                        <votes>0</votes>
                                    <watches>1</watches>
                                                                                                                <comments>
                            <comment id="1425024" author="xgen-internal-githook" created="Thu, 3 Nov 2016 13:45:56 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;username&apos;: u&apos;craiggwilson&apos;, u&apos;name&apos;: u&apos;Craig Wilson&apos;, u&apos;email&apos;: u&apos;craiggwilson@gmail.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-1773&quot; title=&quot;Sample operator throws ArgumentException&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-1773&quot;&gt;&lt;del&gt;CSHARP-1773&lt;/del&gt;&lt;/a&gt;: fix issue with using sample after another pipeline stage.&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/commit/18d204a046373bdceb32f2e17030d3ca8fa12d59&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/commit/18d204a046373bdceb32f2e17030d3ca8fa12d59&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="1424614" author="craiggwilson" created="Wed, 2 Nov 2016 21:40:01 +0000"  >&lt;p&gt;Hi Attila,&lt;/p&gt;

&lt;p&gt;Sorry for the late response. In regards to your question, we do &quot;reimplement&quot; every operator in MongoQueryable. For instance: where -&amp;gt; &lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/blob/master/src/MongoDB.Driver/Linq/MongoQueryable.cs#L2810&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/blob/master/src/MongoDB.Driver/Linq/MongoQueryable.cs#L2810&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;However, the issue was this line:&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/blob/master/src/MongoDB.Driver/Linq/MongoQueryable.cs#L846&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/blob/master/src/MongoDB.Driver/Linq/MongoQueryable.cs#L846&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It should have looked like this:&lt;br/&gt;
Expression.Convert(source.Expression, typeof(IMongoQueryable&amp;lt;TSource&amp;gt;)),&lt;/p&gt;

&lt;p&gt;Will get it fixed.&lt;br/&gt;
Thanks for the report.&lt;br/&gt;
Craig&lt;/p&gt;
</comment>
                            <comment id="1421504" author="enyim" created="Mon, 31 Oct 2016 00:16:54 +0000"  >&lt;p&gt;anyone?&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                        <customfield id="customfield_10011" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Backwards Compatibility</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10011"><![CDATA[Minor Change]]></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_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hrc6qv:</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>
                                                                                                                                                                                                                                                                    <customfield id="customfield_10557" key="com.pyxis.greenhopper.jira:gh-sprint">
                        <customfieldname>Sprint</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue id="1362">C# Sprint 44</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>