Skip to content

Equality of record with private constructor from another assembly gives MethodAccessException #17773

Closed

Description

@ntwilson

We have a codebase with a record with a private constructor. Code in another assembly will equate instances of the record. If both assemblies are compiled with .net 8.0.3, it will work fine. If both assemblies are compiled with 8.0.4, then you will get a runtime exception

System.MethodAccessException : Attempt by method '<caller>' to access method '<record>.Equals(<record>, System.Collections.IEqualityComparer)' failed.

Repro here.
You can see the successful run for 8.0.303 and the failed run for 8.0.401 here

Known workarounds

  • Use .net 8.0.3
  • Make the constructor public

Activity

  1. added this to the Backlog milestone on Sep 20, 2024
  2. vzarytovskii commented on Sep 20, 2024

    @vzarytovskii
    Member

    Duplicate of #17447

    It's suggested to use workarounds described there. I don't think we've backported the fix to 8.0.

    @KevinRansom should we? We probably should.

  3. added
    Area-Compiler-CodeGen
    on Jun 29, 2026
  4. added a commit that references this issue on Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Compiler-CodeGenBug

    Type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions