Skip to content

Compile generated UnsafeAccessors classes don't match underlying class accessibility level #35013

Closed

Description

@NicholasMoss

When using EFOptimizeContext for build-time optimisation and your have an Entity which is less accessible than public the generated UnsafeAccessors class will raise inconsistent accessibility errors.

For example even if the source class is internal the generated UnsafeAccessors class will look something like this:

namespace Financials.Data.Read.Common
{
    public static class TestEntityUnsafeAccessors
    {
        [UnsafeAccessor(UnsafeAccessorKind.Field, Name = "<TestProperty>k__BackingField")]
        public static extern ref string TestProperty(TestEntity @this);
    }
}

Where instead the accessibility of TestEntityUnsafeAccessors should be internal to match the source.

Package: Microsoft.EntityFrameworkCore.Tasks 9.0.0-rc.2.24474.1

Activity

  1. changed the title [-]Compile generated UnsafeAccessors classes don't match underlying class accessibility level (Microsoft.EntityFrameworkCore.Tasks 9.0.0-rc.2.24474.1)[/-] [+]Compile generated UnsafeAccessors classes don't match underlying class accessibility level[/+] on Oct 29, 2024
  2. added this to the 9.0.0 milestone on Oct 29, 2024
  3. modified the milestones: 9.0.0, 10.0.0 on Nov 13, 2024
  4. added theissue type on Jun 15, 2025
  5. qhy040404 commented on Aug 4, 2025

    @qhy040404

    public static class is hard-coded here and is completely unreasonable. And most places (maybe even all places) in the generator of the entire project are directly hard-coded public.

    .Append("public static class ").Append(className);

  6. modified the milestones: 10.0.0, 11.0.0 on Sep 12, 2025
  7. added a commit that references this issue on Jun 18, 2026
    1a62dde
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions