Skip to content

The dotnet framework has a limit of ~64K methods in a single class. #16398

@KevinRansom

Description

@KevinRansom

Whilst investigating: #16039 I encountered this related issue

Source code similar to this ...

namespace Hello

[<NoComparison; NoEquality>]
type Type1() =
    static member Method00001() = ()
    static member Method00002() = ()
    static member Method00003() = ()
    static member Method00004() = ()

    ... including all methods from 00005 to  65517

    static member Method65518() = ()
    static member Method65519() = ()
    static member Method65520() = ()
    static member Method65521() = ()           // Fails at runtime with --- Unhandled exception. System.TypeLoadException: Type 'Hello.Type1' from assembly 'StaticMethods, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' contains more methods than the current implementation allows.

module Main =
  [<EntryPoint>]
  let main _ =
    let t1 = new Type1()
    Type1.Method00001()
    Type1.Method30000()
    Type1.Method60000()
    Type1.Method65000()
    printfn "Fin"
    0

Compiles successfully both release and debug, when it is run the program crashes with the message ....

C:\Users\kevinr\source\repos\ConsoleApp48\StaticMethods>dotnet run -c release
Unhandled exception. System.TypeLoadException: Type 'Hello.Type1' from assembly 'StaticMethods, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' contains more methods than the current implementation allows.
   at Hello.Main.main(String[] _arg1)

Expected, compile time error telling me my program will fail when run, and why.

Program.fs.txt

Metadata

Metadata

Assignees

Labels

Area-LangService-DiagnosticsFCS code analysis, diagnostics, red squiggliesBugImpact-High(Internal MS Team use only) Describes an issue with extreme impact on existing code.

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions