Skip to content

BadImageFormatException when loading a type with a generic constraint on an interface over a multi-dimensional array #137934

Open

Description

@vbreuss

Description

Since .NET 10, the runtime fails to load a type that declares a generic method (or is itself generic) with a constraint on a generic interface whose type argument is a multi-dimensional array, e.g. where T : IFoo<int[,]>. Any use of the type throws System.BadImageFormatException: Bad binary signature. (0x80131192), even calling an unrelated member, so the whole type is unusable.

The same binary runs fine on .NET 9 and on .NET 10.0.0-rc.2, so this is a runtime regression between 10.0.0-rc.2 and 10.0.2, not a compiler issue.

Reproduction Steps

Repro.csproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFrameworks>net9.0;net10.0</TargetFrameworks>
  </PropertyGroup>

</Project>

Program.cs:

using System;

public interface IFoo<T> { }

public static class Broken
{
	public static void Constrained<T>() where T : IFoo<int[,]> { }
	public static string Hello() => "Hello";
}

public static class Program
{
	public static void Main() => Console.WriteLine(Broken.Hello());
}
dotnet build
dotnet exec --fx-version 9.0.18 bin/Debug/net9.0/Repro.dll
dotnet exec --fx-version 10.0.14 bin/Debug/net9.0/Repro.dll

Expected behavior

Hello is printed on every runtime.

Actual behavior

The same net9.0 build:

Runtime Result
9.0.18 Hello
10.0.0-rc.2.25502.107 Hello
10.0.2 Unhandled exception. System.BadImageFormatException: Bad binary signature. (0x80131192) at Program.Main()
10.0.14 same exception
11.0.0 same exception

A net10.0 build behaves the same. The exception is thrown while Main is being compiled, so a try/catch around the call in Main does not catch it.

Variations, each in its own type:

Constraint .NET 8 / 9 .NET 10.0.14 / 11.0.0
where T : IFoo<int[,]> on a method works throws
where T : IFoo<int[,]> on the type (class C<T> where T : IFoo<int[,]>) works throws
where T : IEnumerable<int[,]> (BCL interface) works throws
where T : Bar<int[,]> (class constraint) works works
where T : IFoo<int[]> (single-dimensional array) works works

Regression?

Yes. Works on .NET 9.0.18 and .NET 10.0.0-rc.2.25502.107, fails on .NET 10.0.2 and later (10.0.14 and 11.0.0 tested). 10.0.0 and 10.0.1 were not available to test.

Known Workarounds

None found at the source level. Moving the constrained member into a separate type keeps the rest of the original type usable.

Configuration

  • Windows 11 Pro 10.0.26200, x64
  • .NET SDK 11.0.100
  • Runtimes: Microsoft.NETCore.App 9.0.18, 10.0.0-rc.2.25502.107, 10.0.2, 10.0.14, 11.0.0

Other information

Found through the Mockolate source generator (Testably/Mockolate#1043): generated mock helpers contain Initialize<T>() where T : <mocked interface>, so mocks of generic interfaces closed over a multi-dimensional array (e.g. IRepository<int[,]>) fail to load on .NET 10+.

Activity

  1. MihuBot commented on Nov 19, 2026

    @MihuBot

    I'm a bot. Here is a possible related and/or duplicate issue (I may be wrong):

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions