Skip to content

Invalid custom attribute blob on FSharpList..ctor #15140

@MichalStrehovsky

Description

@MichalStrehovsky

The custom attribute blob on FSharpList..ctor is invalid:

.method assembly specialname rtspecialname 
        instance void  .ctor() cil managed
{
  .custom instance void System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute::.ctor(valuetype System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes,
                                                                                          class [netstandard]System.Type) = ( 01 00 E0 07 00 00 2F 4D 69 63 72 6F 73 6F 66 74   // ....../Microsoft
                                                                                                                              2E 46 53 68 61 72 70 2E 43 6F 6C 6C 65 63 74 69   // .FSharp.Collecti
                                                                                                                              6F 6E 73 2E 46 53 68 61 72 70 4C 69 73 74 60 31   // ons.FSharpList`1
                                                                                                                              5B 5B 21 30 5D 5D 00 00 )                         // [[!0]]..
  .custom instance void [netstandard]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) 
  .custom instance void [netstandard]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) 
  // Code size       7 (0x7)
  .maxstack  8
  IL_0000:  ldarg.0
  IL_0001:  call       instance void [netstandard]System.Object::.ctor()
  IL_0006:  ret
} // end of method FSharpList`1::.ctor

Notice the FSharpList`1[[!0]] part. The intent of the !0 is to represent the first generic argument but that's not something the SerString format supports. See dotnet/runtime#4416 for a spec of the format.

Following C# program throws System.TypeLoadException: 'Could not load type '!0' from assembly 'FSharp.Core, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.' (sorry, I have no clue how to write this in F#):

using System;
using System.Reflection;
using Microsoft.FSharp.Collections;

var attr = typeof(FSharpList<int>).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, Type.EmptyTypes).GetCustomAttributes();
foreach (var a in attr)
    Console.WriteLine(a);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions