Skip to content

RefEmit SymbolMethod should probably have a Metadata token override #53300

@KevinRansom

Description

@KevinRansom

The recent PR to add MedataToken getter overrides to builder classes has broken FSI code generation on dotnet 6.0: Add MetadataToken getter override to builder classes (#43330) · b72b13e (github.com)

The method:

private int GetMethodTokenNoLock(MethodInfo method, bool getGenericTypeDefinition)

was modified here: runtime/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.cs at 01b7e73 · dotnet/runtime (github.com)

This working code:

                if (symMethod.GetModule() == this)
1231
                    return symMethod.GetToken();
1232

Became this failing code:

                if (symMethod.GetModule() == this)
                    return symMethod.MetadataToken;

symMethod is an instance of System.Reflection.Emit.SymbolMethod: here runtime/SymbolMethod.cs at main · dotnet/runtime (github.com)

Which does not provide an override for the MetadataToken property, thus it relies on MemberInfos base implementation which throws a System.InvalidOperationException: 'Operation is not valid due to the current state of the object.'

I assume, someone should either revert the change back to return symMethod.GetToken(); … or provide an overload for MetadataToken on System.Reflection.Emit.SymbolMethod.

Repro:
On a machine with a Net6.0 dotnet sdk installed:

In a command window type:

dotnet fsi

let arr = Array2D.create 3 4 0
let _ = Array2D.get arr 0 0
;;

observe the output:

error FS0193: internal error: Operation is not valid due to the current state of the object.

You may see a bunch of warnings on fsi startup like this, this is an unrelated bug, a fix is in the pipeline:

unknown(1,1): warning FS3384: The .NET SDK for this script could not be determined. If the script is in a directory using a 'global.json' then ensure the relevant .NET SDK is installed. Unexpected error 'Could not find a part of the path 'C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\0.0.0.0\ref'.'.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions