{"record":{"id":"25743e9203bb590c","repo":"microsoft/aspire","slug":"at-least-one-of-nameof-buildimage-or-nameof-runtimeimage","errorCode":null,"errorMessage":"At least one of {nameof(buildImage)} or {nameof(runtimeImage)} must be specified.","messagePattern":"At least one of (.+?) or (.+?) must be specified\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/ContainerResourceBuilderExtensions.cs","lineNumber":1849,"sourceCode":"    ///\n    /// builder.AddPythonApp(\"myapp\", \"path/to/app\", \"main.py\")\n    ///        .WithDockerfileBaseImage(\n    ///            buildImage: \"ghcr.io/astral-sh/uv:python3.12-bookworm-slim\",\n    ///            runtimeImage: \"python:3.12-slim-bookworm\");\n    ///\n    /// builder.Build().Run();\n    /// </code>\n    /// </example>\n    /// </remarks>\n    [AspireExport]\n    [Experimental(\"ASPIREDOCKERFILEBUILDER001\", UrlFormat = \"https://aka.ms/aspire/diagnostics/{0}\")]\n    public static IResourceBuilder<T> WithDockerfileBaseImage<T>(this IResourceBuilder<T> builder, string? buildImage = null, string? runtimeImage = null) where T : IResource\n    {\n        ArgumentNullException.ThrowIfNull(builder);\n\n        if (buildImage is null && runtimeImage is null)\n        {\n            throw new ArgumentException($\"At least one of {nameof(buildImage)} or {nameof(runtimeImage)} must be specified.\", nameof(buildImage));\n        }\n\n        return builder.WithAnnotation(new DockerfileBaseImageAnnotation\n        {\n            BuildImage = buildImage,\n            RuntimeImage = runtimeImage\n        }, ResourceAnnotationMutationBehavior.Replace);\n    }\n\n    /// <summary>\n    /// Adds a network alias to container resource.\n    /// </summary>\n    /// <typeparam name=\"T\">The type of container resource.</typeparam>\n    /// <param name=\"builder\">The resource builder for the container resource.</param>\n    /// <param name=\"alias\">The network alias for the container.</param>\n    /// <returns>The <see cref=\"IResourceBuilder{T}\"/>.</returns>\n    /// <ats-returns>The resource builder.</ats-returns>\n    /// <remarks>","sourceCodeStart":1831,"sourceCodeEnd":1867,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/ContainerResourceBuilderExtensions.cs#L1831-L1867","documentation":"WithDockerfileBaseImage lets you override the base image in the build stage and/or the final runtime stage of a Dockerfile via a DockerfileBaseImageAnnotation. Calling it with both parameters null leaves nothing to override, so ArgumentException is thrown immediately.","triggerScenarios":"Calling .WithDockerfileBaseImage() with no arguments; passing null variables for both buildImage and runtimeImage, e.g. values read from config that were absent.","commonSituations":"Making both images configurable from settings where neither key is set; refactoring away one of the two parameters and dropping the other; a helper wrapper forwarding nullable options without a default.","solutions":["Pass at least one non-null image name, e.g. .WithDockerfileBaseImage(buildImage: \"mcr.microsoft.com/dotnet/sdk:10.0\")","Guard in wrapper code: only call WithDockerfileBaseImage when at least one image is resolved","Provide a default runtime image when the build image is unavailable"],"exampleFix":"// before\nvar build = cfg[\"BuildImage\"];\nvar runtime = cfg[\"RuntimeImage\"]; // both null\nbuilder.WithDockerfileBaseImage(build, runtime);\n// after\nif (build is not null || runtime is not null)\n{\n    builder.WithDockerfileBaseImage(build, runtime);\n}","handlingStrategy":"validation","validationCode":"if (buildImage is null && runtimeImage is null)\n    throw new ArgumentException(\"At least one of buildImage/runtimeImage is required.\");\nbuilder.WithDockerfileBaseImage(buildImage, runtimeImage);","typeGuard":null,"tryCatchPattern":"try { builder.WithDockerfileBaseImage(build, runtime); }\ncatch (ArgumentException ex) when (ex.ParamName == \"buildImage\") { /* provide a default image */ }","preventionTips":["Only call WithDockerfileBaseImage when at least one image is resolved from settings","Provide sensible defaults for build/runtime images in configuration","Keep the call inside the guard, not with unconditional null arguments"],"tags":["dockerfile","base-image","argument-validation"],"backgroundTag":"missing-required-argument","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}