Skip to content

VerifyJson throws PlatformNotSupportedException in AOT (Dynamic code generation is not supported) #1526

@7amou3

Description

@7amou3

Description:

When running tests against an AOT build, calling await VerifyJson(responseBody); fails with:

System.PlatformNotSupportedException : Dynamic code generation is not supported on this platform.

This appears to come from Verify’s default JSON serialization, which relies on dynamic code generation (Emit). That path isn’t available under NativeAOT or trimming.

Repro steps:

  • Create a test project referencing Verify.Xunit and Verify.Json.
  • Enable AOT:
    <PropertyGroup>
        <PublishAot>true</PublishAot>
     </PropertyGroup>
    
  • Run a test:
    [Fact]
    public Task Sample()
    {
        var responseBody = "{\"hello\":\"world\"}";
        return VerifyJson(responseBody);
    }
    
  • Run under AOT → crash with PlatformNotSupportedException.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions