{"record":{"id":"09e373dba676f0d6","repo":"SixLabors/ImageSharp","slug":"this-method-is-used-for-aot-code-generation-only-do-not-call","errorCode":null,"errorMessage":"This method is used for AOT code generation only. Do not call it at runtime.","messagePattern":"This method is used for AOT code generation only\\. Do not call it at runtime\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/Advanced/AotCompilerTools.cs","lineNumber":131,"sourceCode":"            Seed<Rgb48>();\n            Seed<Rgb96>();\n            Seed<Rgba1010102>();\n            Seed<Rgba128>();\n            Seed<Rgba32>();\n            Seed<Rgba32P>();\n            Seed<Rgba64>();\n            Seed<RgbaHalf>();\n            Seed<RgbaHalfP>();\n            Seed<RgbaVector>();\n            Seed<Short2>();\n            Seed<Short4>();\n        }\n        catch\n        {\n            // nop\n        }\n\n        throw new InvalidOperationException(\"This method is used for AOT code generation only. Do not call it at runtime.\");\n    }\n\n    /// <summary>\n    /// Seeds the modern .NET AOT compiler with bulk pixel operations for every built-in pixel format.\n    /// </summary>\n    /// <exception cref=\"InvalidOperationException\">\n    /// This method is used for AOT code generation only. Do not call it at runtime.\n    /// </exception>\n    [Preserve]\n    public static void SeedPixelOperations()\n    {\n        try\n        {\n            // Keep this inventory finite and explicit. ImageSharp cannot precompile consumer-defined pixel types, while\n            // these closed calls make every built-in specialization visible without retaining the much larger legacy seed graph.\n            AotCompilePixelOperations<A8>();\n            AotCompilePixelOperations<Argb32>();\n            AotCompilePixelOperations<Argb32P>();","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/Advanced/AotCompilerTools.cs#L113-L149","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nAotCompilerTools.SeedPixelFormats(); // in startup code\n// after\n// removed — this method is only consumed by the AOT compiler during publish\n","handlingStrategy":"validation","validationCode":"if (Environment.GetEnvironmentVariable(\"CI\") is not null && callingSeeding) throw new NotSupportedException(\"SeedPixelFormats is AOT-only\");","typeGuard":null,"tryCatchPattern":"try { AotCompilerTools.SeedPixelFormats(); }\ncatch (InvalidOperationException) { /* AOT-only method invoked at runtime — remove the call */ }","preventionTips":["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"],"tags":["aot","runtime-error","unsupported-operation","dotnet"],"backgroundTag":"unsupported-operation","analyzedSha":"59ce6af6fc29027cda277ef62d4d1694a8acce91","analyzedAt":"2026-09-13T18:34:59.331Z","contentChangedAt":"2026-09-13T18:34:59.331Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}