SixLabors/ImageSharp · error · InvalidOperationException
This method is used for AOT code generation only. Do not…
Error message
This method is used for AOT code generation only. Do not call it at runtime.
What it means
AotCompilerTools.SeedPixelFormats exists solely so the AOT compiler can generate code for all built-in pixel formats at publish time. If it is ever executed at runtime it deliberately throws InvalidOperationException because its body is not meant to run and its catch-all swallows the seeding calls.
Solutions
- Remove the runtime call — it is only for AOT compilation (dotnet publish with AOT), never runtime
- If you need pixel-format seeding at runtime, nothing is required: the library seeds formats lazily on first use
- Exclude the call from test harnesses that enumerate and invoke public static methods
Example fix
// before AotCompilerTools.SeedPixelFormats(); // in startup code // after // removed — this method is only consumed by the AOT compiler during publish
Defensive patterns
Strategy: validation
Validate before calling
if (Environment.GetEnvironmentVariable("CI") is not null && callingSeeding) throw new NotSupportedException("SeedPixelFormats is AOT-only"); Try / catch
try { AotCompilerTools.SeedPixelFormats(); }
catch (InvalidOperationException) { /* AOT-only method invoked at runtime — remove the call */ } Prevention
- Read API docs before calling AotCompilerTools members — they are compiler aids, not runtime APIs
- Exclude internal tooling classes from reflection-driven smoke tests
- Only reference these methods in publish-time/AOT toolchain contexts
When it happens
Trigger: Explicitly calling AotCompilerTools.SeedPixelFormats() in normal runtime code; calling it in unit tests or reflection-based tooling instead of letting the AOT toolchain consume it.
Common situations: Misunderstanding the API's purpose when doing ahead-of-time trimming on iOS/WebAssembly/Unity IL2CPP; accidentally invoking all public methods of a class in a smoke test; copy-pasting AOT seeding code into a startup path.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Cannot read from the stream.
- {message}
- (invalid memory operation)
- Image cannot be loaded. Available decoders
- Could not find any converter for JpegColorSpace
AI-assisted analysis of SixLabors/ImageSharp@59ce6af6fc (2026-09-13).
Data as JSON: /api/errors/09e373dba676f0d6.
Report an issue: GitHub.
Appendix: source
Thrown at src/ImageSharp/Advanced/AotCompilerTools.cs:131
Seed<Rgb48>();
Seed<Rgb96>();
Seed<Rgba1010102>();
Seed<Rgba128>();
Seed<Rgba32>();
Seed<Rgba32P>();
Seed<Rgba64>();
Seed<RgbaHalf>();
Seed<RgbaHalfP>();
Seed<RgbaVector>();
Seed<Short2>();
Seed<Short4>();
}
catch
{
// nop
}
throw new InvalidOperationException("This method is used for AOT code generation only. Do not call it at runtime.");
}
/// <summary>
/// Seeds the modern .NET AOT compiler with bulk pixel operations for every built-in pixel format.
/// </summary>
/// <exception cref="InvalidOperationException">
/// This method is used for AOT code generation only. Do not call it at runtime.
/// </exception>
[Preserve]
public static void SeedPixelOperations()
{
try
{
// Keep this inventory finite and explicit. ImageSharp cannot precompile consumer-defined pixel types, while
// these closed calls make every built-in specialization visible without retaining the much larger legacy seed graph.
AotCompilePixelOperations<A8>();
AotCompilePixelOperations<Argb32>();
AotCompilePixelOperations<Argb32P>();View on GitHub (pinned to 59ce6af6fc)