<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:42:31 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-2422] Dynamic Linq expression with ParameterExpression would throw value can not be null Exception if ParameterName not set</title>
                <link>https://jira.mongodb.org/browse/CSHARP-2422</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;Dynamically create a Expression, Define the parameter of the Expression as below&lt;/p&gt;

&lt;p&gt;var parameter = Expression.Parameter(typeof(T));&lt;/p&gt;

&lt;p&gt;then pass this expression to MongoQueryable.Where function&lt;/p&gt;

&lt;p&gt;call Count or ToList&lt;/p&gt;

&lt;p&gt;reported the below exception&lt;/p&gt;

&lt;p&gt;Value cannot be null.&lt;br/&gt;
Parameter name: itemName&lt;/p&gt;

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

&lt;p&gt;on the other hand, if i declare the parameter of the expression as below&lt;/p&gt;

&lt;p&gt;var parameter = Expression.Parameter(typeof(T),&quot;item&quot;);&lt;/p&gt;

&lt;p&gt;then the linq expression can be successfully transformed to mongodb query&lt;/p&gt;

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

&lt;p&gt;while transform the linq expression to mongodb query, why does the parameter name is required? when it comes to dynamically generated expression people usually use anonymous parameter and the exception message does not explicitly indicate the parameter expression need a name.&#160;&lt;/p&gt;</description>
                <environment></environment>
        <key id="623931">CSHARP-2422</key>
            <summary>Dynamic Linq expression with ParameterExpression would throw value can not be null Exception if ParameterName not set</summary>
                <type id="4" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14710&amp;avatarType=issuetype">Improvement</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="13201">Fixed</resolution>
                                        <assignee username="robert@mongodb.com">Robert Stam</assignee>
                                    <reporter username="elendil">elendil</reporter>
                        <labels>
                    </labels>
                <created>Thu, 25 Oct 2018 05:20:38 +0000</created>
                <updated>Sat, 28 Oct 2023 11:48:54 +0000</updated>
                            <resolved>Mon, 25 Oct 2021 15:18:38 +0000</resolved>
                                                    <fixVersion>2.14.0</fixVersion>
                                    <component>Linq</component>
                                        <votes>0</votes>
                                    <watches>6</watches>
                                                                                                                <comments>
                            <comment id="4145625" author="JIRAUSER1259588" created="Mon, 25 Oct 2021 15:30:02 +0000"  >&lt;p&gt;Thanks!&lt;/p&gt;</comment>
                            <comment id="4145563" author="rstam" created="Mon, 25 Oct 2021 15:18:38 +0000"  >&lt;p&gt;This issue has been fixed in the new LINQ provider (known as LINQ3) which will be included in the upcoming 2.14 release.&lt;/p&gt;

&lt;p&gt;Configure your &lt;tt&gt;MongoClientSettings&lt;/tt&gt; to use &lt;tt&gt;LinqProvider.V3&lt;/tt&gt; if you want to use this functionality.&lt;/p&gt;

&lt;p&gt;To configure a client to use the LINQ3 provider use code like the following&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 connectionString = &quot;mongodb://localhost&quot;;&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 clientSettings = MongoClientSettings.FromConnectionString(connectionString);&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;clientSettings.LinqProvider = LinqProvider.V3;&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;var client = new MongoClient(clientSettings);&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;</comment>
                            <comment id="4145560" author="xgen-internal-githook" created="Mon, 25 Oct 2021 15:18:15 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;rstam&apos;, &apos;email&apos;: &apos;robert@robertstam.org&apos;, &apos;username&apos;: &apos;rstam&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-2422&quot; title=&quot;Dynamic Linq expression with ParameterExpression would throw value can not be null Exception if ParameterName not set&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-2422&quot;&gt;&lt;del&gt;CSHARP-2422&lt;/del&gt;&lt;/a&gt;: Verify that dynamic predicates with null parameterNames work in LINQ3.&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/commit/ec5da32d3418f87cd158705caeec9d3dd741b02a&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/commit/ec5da32d3418f87cd158705caeec9d3dd741b02a&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="3755350" author="rstam" created="Tue, 4 May 2021 21:15:50 +0000"  >&lt;p&gt;It&apos;s a surprise to us that `ParameterExpression.Name` can be `null`, but looking at the documentation I agree with you that it is legal for `Name` to be `null`.&lt;/p&gt;

&lt;p&gt;We are currently writing a new LINQ provider. We won&apos;t retrofit the existing LINQ provider to support `null` parameter names, but we will make sure this is supported by the new LINQ provider.&lt;/p&gt;</comment>
                            <comment id="3734517" author="JIRAUSER1259588" created="Thu, 22 Apr 2021 22:37:52 +0000"  >&lt;p&gt;I agree with&#160;&#1053;&#1080;&#1082;&#1086;&#1083;&#1072;&#1081; &#1064;&#1084;&#1072;&#1090;&#1077;&#1085;&#1082;&#1086;&#1074;. The inconsistency in behavior of LINQ translator indicates a bug, rather than a designed feature.&lt;/p&gt;

&lt;p&gt;I also believe that providing parameter name when creating a parameter expression is not required for the expression to be correct and suitable for translating. Other query providers like EF Core use their own parameter names anyway.&lt;/p&gt;

&lt;p&gt;&#160;The documentation about &lt;tt&gt;name&lt;/tt&gt; parameter in &lt;tt&gt;Expression.Parameter(Type type, string name)&lt;/tt&gt; method:&lt;/p&gt;

&lt;p&gt;&amp;gt; &lt;em&gt;The name of the parameter or variable, used for debugging or printing purpose only.&lt;/em&gt; ~ &lt;a href=&quot;https://docs.microsoft.com/en-us/dotnet/api/system.linq.expressions.expression.parameter?view=net-5.0#System_Linq_Expressions_Expression_Parameter_System_Type_System_String_&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;Docs&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="3734335" author="JIRAUSER1259592" created="Thu, 22 Apr 2021 21:07:52 +0000"  >&lt;p&gt;But if I pass same expression into a where clause of some filter builder it works fine. What means - this is a bug, not a designed feature.&lt;/p&gt;</comment>
                            <comment id="3734313" author="mikalai.mazurenka" created="Thu, 22 Apr 2021 20:57:10 +0000"  >&lt;p&gt;Our LINQ translator handles this case just fine if you use expression lambda.&lt;br/&gt;
In case you want to build the expression yourself, be sure it is correct and equivalent to what expression lambda would create.&lt;br/&gt;
For this particular case that means explicitly specifying the parameter name.&lt;/p&gt;</comment>
                            <comment id="3732419" author="JIRAUSER1259588" created="Thu, 22 Apr 2021 09:27:37 +0000"  >&lt;p&gt;Hi,&lt;/p&gt;

&lt;p&gt;I&apos;ve also came across this bug. I also confirm that explicitly specifying the parameter name works as a workaround this problem.&lt;/p&gt;

&lt;p&gt;Here is a full repro&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://gist.github.com/Prologh/164ca4ccf24423d70c2087aeb397430f&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://gist.github.com/Prologh/164ca4ccf24423d70c2087aeb397430f&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="2513471" author="hdurrani@lstyazilim.com" created="Thu, 31 Oct 2019 22:28:20 +0000"  >&lt;p&gt;Hi,&lt;/p&gt;

&lt;p&gt;I am also having this problem i am trying to create a daynamic where clause for my query by using expression. if i create&#160;ParameterExpression variable using&#160;Expression.Parameter(typeof(MyObject)); i get the error&#160;&quot;Value cannot be null. (Parameter &apos;itemName&apos;)&quot; on ToListAsync but if i create it&#160;Expression.Parameter(typeof(VanInformation),&quot;Abc&quot;); then i dont get error but also my filter doenot work. can anyone help me to solve this problem.&lt;/p&gt;</comment>
                            <comment id="2083501" author="jeff.yemin" created="Fri, 7 Dec 2018 01:57:40 +0000"  >&lt;p&gt;As we haven&apos;t heard back from you, we&apos;re closing this issue.  If you are able to provide more details, we&apos;ll be happy to re-open it.&lt;/p&gt;</comment>
                            <comment id="2052378" author="rstam" created="Mon, 5 Nov 2018 20:24:13 +0000"  >&lt;p&gt;Can you please provide sample code that can be compiled and run to reproduce this with?&lt;/p&gt;

&lt;p&gt;We&apos;re not quite sure from your description how to reproduce this.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10011">
                    <name>Depends</name>
                                            <outwardlinks description="depends on">
                                        <issuelink>
            <issuekey id="1701033">CSHARP-3648</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                                                <inwardlinks description="is duplicated by">
                                        <issuelink>
            <issuekey id="1687148">CSHARP-3603</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </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|hu1gz3:</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>