Skip to content

MethodAccessException on equality comparison of a record with private fields #17447

Closed
@iminashi

Description

Equality comparison of a record type with private fields no longer works in SDK 8.0.400 for a type that is in a different assembly.

Repro steps

Assembly A:

Record type with private fields.

module Types

type Value =
    private { value: uint32 }

    static member Zero = { value = 0u }
    static member Create(value: int) = { value = uint value }

Assembly B:

Anything that uses the = operator on the type.

module Test

open NUnit.Framework
open Types

[<Test>]
let Equality () =
    let zero = Value.Create 0

    Assert.That(Value.Zero = zero, "zero equals zero")

Expected behavior

Equality comparison works.

Actual behavior

Runtime exception:

System.MethodAccessException : Attempt by method 'Test.Equality()' to access method 'Types+Value.Equals(Value, System.Collections.IEqualityComparer)' failed.

Known workarounds

  • Remove the private modifier.
  • Replace = with Equals call.

Related information

  • .NET SDK 8.0.400-preview.0.24324.5

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions