System.Linq.Dynamic.Core icon indicating copy to clipboard operation
System.Linq.Dynamic.Core copied to clipboard

Dynamic queries cannot access internal properties even with InternalsVisibleTo

Open pirumar opened this issue 4 months ago • 3 comments

Describe the bug

When using dynamic queries in System.Linq.Dynamic.Core, I am not able to access internal properties of my entity classes.
Even though I added [assembly: InternalsVisibleTo("DynamicLinqTest")] (or the corresponding consuming assembly name), the dynamic parser still throws an error that the property does not exist.


To Reproduce

Steps to reproduce the behavior:

  1. Create a class with an internal property: public class MyEntity { internal string InternalProp { get; set; } = "test"; }
  2. Add InternalsVisibleTo to the assembly: [assembly: InternalsVisibleTo("DynamicLinqTest")]
  3. Try to query dynamically: var query = entities.AsQueryable().Where("InternalProp == \"test\"");
  4. Observe that it fails with: No property or field 'InternalProp' exists in type 'MyEntity'

Expected behavior

Dynamic query parser should respect InternalsVisibleTo and allow access to internal properties if visibility has been granted.

Additional context

  • Reflection-based access from the same assembly works fine.
  • The limitation seems to come from the binding logic inside Dynamic.Core not considering internal properties, even with InternalsVisibleTo applied.

Would it be possible to support this scenario, or at least provide an option to enable it?

pirumar avatar Sep 08 '25 07:09 pirumar

I added this support, but I can't send it by creating a branch due to permissions.

Image Image

pirumar avatar Sep 09 '25 14:09 pirumar

You need to fork this repository. Create a new branch. And create a Pull Request from your forked branch to this project.

StefH avatar Sep 09 '25 15:09 StefH

@StefH Sorry, I was distracted, I created the PR correctly. Add AllowAccessToNonPublicMembers property to ParsingConfig

pirumar avatar Sep 09 '25 15:09 pirumar