You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using Select("...") on an IQueryable of anonymous object elements that were created by Select("new { ... }") throws System.InvalidOperationException: 'The result of the dynamic binding produced by the object with type '<>f__AnonymousType0`1' for the binder 'System.Linq.Dynamic.Core.DynamicGetMemberBinder' needs at least one restriction.'
Note that using Select("...") on an IQueryable of anonymous object elements that were created statically in code works as expected.
Exception
System.InvalidOperationException
HResult=0x80131509
Message=The result of the dynamic binding produced by the object with type '<>f__AnonymousType0`1' for the binder 'System.Linq.Dynamic.Core.DynamicGetMemberBinder' needs at least one restriction.
Source=System.Linq.Expressions
StackTrace:
at System.Dynamic.DynamicMetaObjectBinder.Bind(Object[] args, ReadOnlyCollection`1 parameters, LabelTarget returnLabel) in /_/src/libraries/System.Linq.Expressions/src/System/Dynamic/DynamicMetaObjectBinder.cs:line 116
at System.Runtime.CompilerServices.CallSiteBinder.BindCore[T](CallSite`1 site, Object[] args) in /_/src/libraries/System.Linq.Expressions/src/System/Runtime/CompilerServices/CallSiteBinder.cs:line 120
at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0) in /_/src/libraries/System.Linq.Expressions/src/System/Dynamic/UpdateDelegates.Generated.cs:line 115
at System.Linq.Enumerable.SelectArrayIterator`2.MoveNext() in /_/src/libraries/System.Linq/src/System/Linq/Select.cs:line 191
at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items) in /_/src/libraries/Common/src/System/Collections/Generic/LargeArrayBuilder.SpeedOpt.cs:line 112
at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source) in /_/src/libraries/Common/src/System/Collections/Generic/EnumerableHelpers.Linq.cs:line 84
at System.Linq.Dynamic.Core.DynamicEnumerableExtensions.CastToArray[T](IEnumerable source)
at System.Linq.Dynamic.Core.DynamicEnumerableExtensions.ToDynamicArray(IEnumerable source)
at DynamicLinqExamples.SelectProjection.Execute() in C:\Users\JoshuaHelm\dev\DynamicLinqBugExamples\SelectProjection.cs:line 23
at DynamicLinqExamples.Program.Main(String[] args) in C:\Users\JoshuaHelm\dev\DynamicLinqBugExamples\Program.cs:line 11
Repro
// worksvarstaticData=new[]{1,2}.AsQueryable().Select(x =>new{Value=x}).ToDynamicArray();varstaticResult=staticData.AsQueryable().Select("Value").ToDynamicArray();// throws System.InvalidOperationException: 'The result of the dynamic binding produced by the object with type '<>f__AnonymousType0`1' for the binder 'System.Linq.Dynamic.Core.DynamicGetMemberBinder' needs at least one restriction.'vardynamicData=new[]{1,2}.AsQueryable().Select("new { it as Value }").ToDynamicArray();vardynamicResult=dynamicData.AsQueryable().Select("Value").ToDynamicArray();
Technical details
System.Linq.Dynamic.Core 1.6.0.2
.NET 8.0 and 9.0
Thanks!
The text was updated successfully, but these errors were encountered:
jbhelm
changed the title
Select("...") from an IQueryable of anonymous objects created via Select("new { ... }") fields with InvalidOperationException
Select("...") from an IQueryable of anonymous objects created via Select("new { ... }") throws InvalidOperationException
Mar 27, 2025
Description
Using
Select("...")
on an IQueryable of anonymous object elements that were created bySelect("new { ... }")
throws System.InvalidOperationException: 'The result of the dynamic binding produced by the object with type '<>f__AnonymousType0`1' for the binder 'System.Linq.Dynamic.Core.DynamicGetMemberBinder' needs at least one restriction.'Note that using
Select("...")
on an IQueryable of anonymous object elements that were created statically in code works as expected.Exception
Repro
Technical details
Thanks!
The text was updated successfully, but these errors were encountered: