Dynamic Select() broken on 6.1.4 #1652

Closed
opened 2026-01-29 17:56:46 +00:00 by claunia · 11 comments
Owner

Originally created by @XorZy on GitHub (Mar 2, 2025).

Describe the bug
I am trying to switch to Radzen 6.x.
I am aware that the dependency on DynamicLinq has been dropped but the replacement methods do not seem to cover all use cases, even very basic ones.
I use reflection to query specific rows of an entity type.
The following code used to work on Radzen 5

...
return await dbSet.Select($"x=>x.{property.Name}").ToDynamicArrayAsync();

But now it throws this exception :

System.InvalidOperationException: Invalid selector: x=>x_Brand = it.x=>x?.Brand.
 ---> System.NotSupportedException: Unsupported initializer: x=>x_Brand = it.x
   at Radzen.ExpressionSyntaxVisitor.GetPropertyNameFromInitializer(AnonymousObjectMemberDeclaratorSyntax initializer)
   at Radzen.ExpressionSyntaxVisitor.<>c__DisplayClass23_0.<VisitAnonymousObjectCreationExpression>b__0(AnonymousObjectMemberDeclaratorSyntax init)
   at System.Linq.Enumerable.IEnumerableSelectIterator`2.ToList()
   at Radzen.ExpressionSyntaxVisitor.VisitAnonymousObjectCreationExpression(AnonymousObjectCreationExpressionSyntax node)
   at Microsoft.CodeAnalysis.CSharp.Syntax.AnonymousObjectCreationExpressionSyntax.Accept[TResult](CSharpSyntaxVisitor`1 visitor)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor`1.Visit(SyntaxNode node)
   at Radzen.ExpressionParser.Parse[T](String expression, Func`2 typeLocator)
   at Radzen.ExpressionParser.ParseLambda[T](String expression, Func`2 typeLocator)
   at System.Linq.Dynamic.Core.DynamicExtensions.<>c__3`1.<Select>b__3_0(String expression)
   at System.Linq.Dynamic.Core.DynamicExtensions.Select(IQueryable source, String selector, Func`2 lambdaCreator)
   --- End of inner exception stack trace ---
   at System.Linq.Dynamic.Core.DynamicExtensions.Select(IQueryable source, String selector, Func`2 lambdaCreator)
   at System.Linq.Dynamic.Core.DynamicExtensions.Select[T](IQueryable`1 source, String selector, Object[] parameters)

I am not sure why Radzen changes my expression from x=>x.Property to x=>x_Property = it.x=>x?.Property, which seems to be at the source of the issue.

I have added an explicit reference to my csproj, but for some reason the Radzen Extensions Methods are still being used instead.
<PackageReference Include="System.Linq.Dynamic.Core" Version="*" />

Is this use case supported?
And if not how to actually make sure the Radzen Extensions Method are not used?

Originally created by @XorZy on GitHub (Mar 2, 2025). **Describe the bug** I am trying to switch to Radzen 6.x. I am aware that the dependency on DynamicLinq has been dropped but the replacement methods do not seem to cover all use cases, even very basic ones. I use reflection to query specific rows of an entity type. The following code used to work on Radzen 5 ```csharp ... return await dbSet.Select($"x=>x.{property.Name}").ToDynamicArrayAsync(); ``` But now it throws this exception : ```csharp System.InvalidOperationException: Invalid selector: x=>x_Brand = it.x=>x?.Brand. ---> System.NotSupportedException: Unsupported initializer: x=>x_Brand = it.x at Radzen.ExpressionSyntaxVisitor.GetPropertyNameFromInitializer(AnonymousObjectMemberDeclaratorSyntax initializer) at Radzen.ExpressionSyntaxVisitor.<>c__DisplayClass23_0.<VisitAnonymousObjectCreationExpression>b__0(AnonymousObjectMemberDeclaratorSyntax init) at System.Linq.Enumerable.IEnumerableSelectIterator`2.ToList() at Radzen.ExpressionSyntaxVisitor.VisitAnonymousObjectCreationExpression(AnonymousObjectCreationExpressionSyntax node) at Microsoft.CodeAnalysis.CSharp.Syntax.AnonymousObjectCreationExpressionSyntax.Accept[TResult](CSharpSyntaxVisitor`1 visitor) at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor`1.Visit(SyntaxNode node) at Radzen.ExpressionParser.Parse[T](String expression, Func`2 typeLocator) at Radzen.ExpressionParser.ParseLambda[T](String expression, Func`2 typeLocator) at System.Linq.Dynamic.Core.DynamicExtensions.<>c__3`1.<Select>b__3_0(String expression) at System.Linq.Dynamic.Core.DynamicExtensions.Select(IQueryable source, String selector, Func`2 lambdaCreator) --- End of inner exception stack trace --- at System.Linq.Dynamic.Core.DynamicExtensions.Select(IQueryable source, String selector, Func`2 lambdaCreator) at System.Linq.Dynamic.Core.DynamicExtensions.Select[T](IQueryable`1 source, String selector, Object[] parameters) ``` I am not sure why Radzen changes my expression from **x=>x.Property** to **x=>x_Property = it.x=>x?.Property**, which seems to be at the source of the issue. I have added an explicit reference to my csproj, but for some reason the Radzen Extensions Methods are still being used instead. ` <PackageReference Include="System.Linq.Dynamic.Core" Version="*" />` Is this use case supported? And if not how to actually make sure the Radzen Extensions Method are not used?
Author
Owner

@XorZy commented on GitHub (Mar 4, 2025):

Thanks for your quick reply.
I just tried on 6.1.6 and unfortunately it still does not work, the exception is different though:

System.InvalidOperationException: Invalid selector: x=>x.Brand.
 ---> System.ArgumentException: 'Brand' is not a member of type 'System.Object' (Parameter 'propertyOrFieldName')
   at System.Linq.Expressions.Expression.PropertyOrField(Expression expression, String propertyOrFieldName)
   at Radzen.ExpressionSyntaxVisitor.VisitMemberAccessExpression(MemberAccessExpressionSyntax node)
   at Microsoft.CodeAnalysis.CSharp.Syntax.MemberAccessExpressionSyntax.Accept[TResult](CSharpSyntaxVisitor`1 visitor)
   at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor`1.Visit(SyntaxNode node)
   at Radzen.ExpressionParser.Parse[T](String expression, Func`2 typeLocator)
   at Radzen.ExpressionParser.ParseLambda[T](String expression, Func`2 typeLocator)
   at System.Linq.Dynamic.Core.DynamicExtensions.<>c__3`1.<Select>b__3_0(String expression)
   at System.Linq.Dynamic.Core.DynamicExtensions.Select(IQueryable source, String selector, Func`2 lambdaCreator)
   --- End of inner exception stack trace ---
   at System.Linq.Dynamic.Core.DynamicExtensions.Select(IQueryable source, String selector, Func`2 lambdaCreator)
   at System.Linq.Dynamic.Core.DynamicExtensions.Select[T](IQueryable`1 source, String selector, Object[] parameters)
@XorZy commented on GitHub (Mar 4, 2025): Thanks for your quick reply. I just tried on 6.1.6 and unfortunately it still does not work, the exception is different though: ```csharp System.InvalidOperationException: Invalid selector: x=>x.Brand. ---> System.ArgumentException: 'Brand' is not a member of type 'System.Object' (Parameter 'propertyOrFieldName') at System.Linq.Expressions.Expression.PropertyOrField(Expression expression, String propertyOrFieldName) at Radzen.ExpressionSyntaxVisitor.VisitMemberAccessExpression(MemberAccessExpressionSyntax node) at Microsoft.CodeAnalysis.CSharp.Syntax.MemberAccessExpressionSyntax.Accept[TResult](CSharpSyntaxVisitor`1 visitor) at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor`1.Visit(SyntaxNode node) at Radzen.ExpressionParser.Parse[T](String expression, Func`2 typeLocator) at Radzen.ExpressionParser.ParseLambda[T](String expression, Func`2 typeLocator) at System.Linq.Dynamic.Core.DynamicExtensions.<>c__3`1.<Select>b__3_0(String expression) at System.Linq.Dynamic.Core.DynamicExtensions.Select(IQueryable source, String selector, Func`2 lambdaCreator) --- End of inner exception stack trace --- at System.Linq.Dynamic.Core.DynamicExtensions.Select(IQueryable source, String selector, Func`2 lambdaCreator) at System.Linq.Dynamic.Core.DynamicExtensions.Select[T](IQueryable`1 source, String selector, Object[] parameters) ```
Author
Owner

@enchev commented on GitHub (Mar 5, 2025):

Make sure the string is valid C#:

https://forum.radzen.com/t/just-released-our-new-major-version-of-radzen-blazor-6-0-0-without-reference-to-system-linq-dynamic-core-nuget-package/19748?u=enchev

Check if you have instance name in front of the property - i.e.
x => x.Brand

@enchev commented on GitHub (Mar 5, 2025): Make sure the string is valid C#: https://forum.radzen.com/t/just-released-our-new-major-version-of-radzen-blazor-6-0-0-without-reference-to-system-linq-dynamic-core-nuget-package/19748?u=enchev Check if you have instance name in front of the property - i.e. x => x.Brand
Author
Owner

@XorZy commented on GitHub (Mar 5, 2025):

Make sure the string is valid C#:

https://forum.radzen.com/t/just-released-our-new-major-version-of-radzen-blazor-6-0-0-without-reference-to-system-linq-dynamic-core-nuget-package/19748?u=enchev

Check if you have instance name in front of the property - i.e. x => x.Brand

It is valid C# (x=>x.Brand as shown in the exception) and the queried instance has the requested property.
In fact, the code works as-is on 5.9.9 but fails on 6.1.6, with no code change whatsoever.

@XorZy commented on GitHub (Mar 5, 2025): > Make sure the string is valid C#: > > https://forum.radzen.com/t/just-released-our-new-major-version-of-radzen-blazor-6-0-0-without-reference-to-system-linq-dynamic-core-nuget-package/19748?u=enchev > > Check if you have instance name in front of the property - i.e. x => x.Brand It is valid C# (x=>x.Brand as shown in the exception) and the queried instance has the requested property. In fact, the code works as-is on 5.9.9 but fails on 6.1.6, with no code change whatsoever.
Author
Owner

@enchev commented on GitHub (Mar 5, 2025):

What’s the type of x and how this property is defined?

@enchev commented on GitHub (Mar 5, 2025): What’s the type of x and how this property is defined?
Author
Owner

@XorZy commented on GitHub (Mar 5, 2025):

What’s the type of x and how this property is defined?

'x' is a record and the property is defined as follows

public List<Media> Brand { get; set; } = [];

I should note that List<Media> is handled by a custom converter that is registered as follows:

protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
{
        configurationBuilder
            .Properties<List<Media>>()
            .HaveConversion<MediaListConverter, MediaListComparer>();
...
}
@XorZy commented on GitHub (Mar 5, 2025): > What’s the type of x and how this property is defined? 'x' is a record and the property is defined as follows ```csharp public List<Media> Brand { get; set; } = []; ``` I should note that `List<Media> `is handled by a custom converter that is registered as follows: ```csharp protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder) { configurationBuilder .Properties<List<Media>>() .HaveConversion<MediaListConverter, MediaListComparer>(); ... } ```
Author
Owner

@enchev commented on GitHub (Mar 5, 2025):

I've verified once again that the following code works as expected in our demos:

var data = dbContext.Orders.Select("x => x.OrderDetails");

Make sure you have using System.Linq.Dynamic.Core in your class to ensure that our replacement of Dynami LINQ method will be used:

Image

Image

@enchev commented on GitHub (Mar 5, 2025): I've verified once again that the following code works as expected in our demos: ``` var data = dbContext.Orders.Select("x => x.OrderDetails"); ``` Make sure you have `using System.Linq.Dynamic.Core` in your class to ensure that our replacement of Dynami LINQ method will be used: ![Image](https://github.com/user-attachments/assets/73a8119e-48f7-4534-83e4-f61c145ed029) ![Image](https://github.com/user-attachments/assets/b1201a44-883a-4a09-a4eb-2aee66bbe825)
Author
Owner

@XorZy commented on GitHub (Mar 5, 2025):

I cannot share the project but I've managed to create a minimal repro:
https://github.com/XorZy/RadzenExample

In the original project, the DbSet is created via reflection and therefore defaults to an IQueryable<object>.
In the repro this is emulated with Cast<object>().
This does not appear to be a problem for the original Dynamic Linq implementation, but it is for the Radzen extensions methods.
I should note it works as expected without the cast but as I said before the type is not know at compile time in the original project.

Please observe in the attached repro that even though there is an explicit reference
<PackageReference Include="System.Linq.Dynamic.Core" Version="*" />, the Radzen extension methods are still being used.

Commenting out the Radzen Packages Reference allows the example to run as expected.

@XorZy commented on GitHub (Mar 5, 2025): I cannot share the project but I've managed to create a minimal repro: https://github.com/XorZy/RadzenExample In the original project, the DbSet is created via reflection and therefore defaults to an `IQueryable<object>`. In the repro this is emulated with `Cast<object>()`. This does not appear to be a problem for the original Dynamic Linq implementation, but it is for the Radzen extensions methods. I should note it works as expected without the cast but as I said before the type is not know at compile time in the original project. Please observe in the attached repro that even though there is an explicit reference `<PackageReference Include="System.Linq.Dynamic.Core" Version="*" />`, the Radzen extension methods are still being used. Commenting out the Radzen Packages Reference allows the example to run as expected.
Author
Owner

@enchev commented on GitHub (Mar 5, 2025):

This should resolve the problem - let me know:
d52d91852a

@enchev commented on GitHub (Mar 5, 2025): This should resolve the problem - let me know: https://github.com/radzenhq/radzen-blazor/commit/d52d91852a2a2d90338515ee7777e3251c6f8af5
Author
Owner

@XorZy commented on GitHub (Mar 5, 2025):

This should resolve the problem - let me know: d52d918

Okay so it works in the repro but not in my project.
The problem seems to be that a DbSet (unlike .AsQueryable()) actually sets ElementType to the actual object type and not typeof(object) like in my repro.
(<T> is still typeof(object))

@XorZy commented on GitHub (Mar 5, 2025): > This should resolve the problem - let me know: [d52d918](https://github.com/radzenhq/radzen-blazor/commit/d52d91852a2a2d90338515ee7777e3251c6f8af5) Okay so it works in the repro but not in my project. The problem seems to be that a DbSet (unlike .AsQueryable()) actually sets ElementType to the actual object type and not typeof(object) like in my repro. (`<T>` is still typeof(object))
Author
Owner

@enchev commented on GitHub (Mar 5, 2025):

I'm afraid that I don't have other ideas. If you have any - we accept pull requests.

@enchev commented on GitHub (Mar 5, 2025): I'm afraid that I don't have other ideas. If you have any - we accept pull requests.
Author
Owner

@XorZy commented on GitHub (Mar 5, 2025):

I'm afraid that I don't have other ideas. If you have any - we accept pull requests.

I've created a PR which addresses my specific use case, let me know what you think

@XorZy commented on GitHub (Mar 5, 2025): > I'm afraid that I don't have other ideas. If you have any - we accept pull requests. I've created a [PR](https://github.com/radzenhq/radzen-blazor/pull/2017) which addresses my specific use case, let me know what you think
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#1652