Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List constructs EF uses that require non-public code access #29843

Closed
ajcvickers opened this issue Dec 13, 2022 · 5 comments
Closed

List constructs EF uses that require non-public code access #29843

ajcvickers opened this issue Dec 13, 2022 · 5 comments
Labels
area-aot closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-unknown
Milestone

Comments

@ajcvickers
Copy link
Member

Put together a list of everything we do that operates on non-public code when we would not normally have permission to do so.

@ajcvickers
Copy link
Member Author

Code that compiles expression trees:

@ajcvickers
Copy link
Member Author

ajcvickers commented Jan 10, 2023

Based on the code above, we need to be able to:

  • Read and write from properties and fields with any visibility
    • Highest priority
  • Call constructors, both parameterless and with parameters with any visibility
    • Medium priority--needed for relatively common scenarios, but can be worked around with application code changes
  • Call methods with any visibility
    • Low priority--not used in common scenarios
  • These operations may be done on both reference and value types, which themselves may have any visibility
  • Fields may be compiler-generated and so not have valid C# identifiers
  • Fields may be marked as readonly

Beyond this, applications and database providers can inject their own expressions in various places, and these may contain arbitrary code. However, I believe we can limit this code to the cases above and throw (or use Reflection) if injected code does anything else.

@AndriySvyryd
Copy link
Member

As for the shape of the API we'd prefer to be able to use just the name string and declaring type to access properties and fields instead of PropertyInfo/FieldInfo

@roji
Copy link
Member

roji commented Jan 10, 2023

Fields may be compiler-generated and so not have valid C# identifiers

As discussed offline, let's ask for a way to access backing fields of auto-properties. This isn't critical: we can use the regular API for accessing private fields, passing it the compiler-generated name (as today). But it would be good to remove knowledge of compiled-generated names from EF.

The two API options for this would be:

  1. A dedicated API returning the name of the backing field, given a property. The slight disadvantage for us would be to embed the compiler-generated name obtained from this API in our generated C# code.
  2. APIs accepting the property and directly reading/writing its backing field (assuming its an auto-property). The consumer would have to know they're accessing an auto-property (via another API? Or this API would be some sort of TryReadXXX, returning false for non-auto-properties?). This would also require us to generate different access code for auto-properties and other things.

So option 1 seems to be the preferred way for us, in any case.

@ajcvickers
Copy link
Member Author

See dotnet/runtime#81741

@ajcvickers ajcvickers added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Feb 11, 2023
@ajcvickers ajcvickers modified the milestones: 8.0.0, 8.0.0-preview2 Feb 16, 2023
@ajcvickers ajcvickers modified the milestones: 8.0.0-preview2, 8.0.0 Nov 14, 2023
@ajcvickers ajcvickers removed their assignment Aug 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-aot closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-unknown
Projects
None yet
Development

No branches or pull requests

3 participants