{"record":{"id":"8b8ef0a23085bee2","repo":"dotnet/wpf","slug":"image-guidempty-containerformat","errorCode":null,"errorMessage":"Image_GuidEmpty (containerFormat)","messagePattern":"Image_GuidEmpty \\(containerFormat\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapEncoder.cs","lineNumber":75,"sourceCode":"        }\n\n        /// <summary>\n        /// Internal Constructor.\n        /// </summary>\n        internal BitmapEncoder(bool isBuiltIn)\n        {\n            _isBuiltIn = isBuiltIn;\n        }\n\n        /// <summary>\n        /// Creates a BitmapEncoder from a container format Guid\n        /// </summary>\n        /// <param name=\"containerFormat\">Container format for the codec</param>\n        public static BitmapEncoder Create(Guid containerFormat)\n        {\n            if (containerFormat == Guid.Empty)\n            {\n                throw new ArgumentException(\n                    SR.Format(SR.Image_GuidEmpty, \"containerFormat\"),\n                    nameof(containerFormat)\n                    );\n            }\n            else if (containerFormat == MILGuidData.GUID_ContainerFormatBmp)\n            {\n                return new BmpBitmapEncoder();\n            }\n            else if (containerFormat == MILGuidData.GUID_ContainerFormatGif)\n            {\n                return new GifBitmapEncoder();\n            }\n            else if (containerFormat == MILGuidData.GUID_ContainerFormatJpeg)\n            {\n                return new JpegBitmapEncoder();\n            }\n            else if (containerFormat == MILGuidData.GUID_ContainerFormatPng)\n            {","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapEncoder.cs#L57-L93","documentation":"BitmapEncoder.Create(Guid containerFormat) validates that the container format GUID is non-empty; Guid.Empty is not a registered codec container and would fail WIC lookup, so an ArgumentException named Image_GuidEmpty is thrown for the containerFormat parameter.","triggerScenarios":"Calling BitmapEncoder.Create(Guid.Empty) or passing a default(Guid) (e.g. an uninitialized struct field or failed lookup result) as the container format.","commonSituations":"Resolving a format GUID from config/registry/strings and failing to populate it; using Guid.Empty as a placeholder; deriving the GUID from a codec ID lookup that returned nothing.","solutions":["Pass a known container GUID such as MILGuidData.GUID_ContainerFormatPng/Bmp/Jpeg/Tiff/Wmp","Use a concrete encoder type (e.g. new PngBitmapEncoder()) instead of Create","Validate the GUID with Guid.Empty checks before calling Create","Verify the string->Guid conversion used to obtain the format actually succeeded"],"exampleFix":"// before\nvar enc = BitmapEncoder.Create(default(Guid));\n// after\nvar enc = BitmapEncoder.Create(MILGuidData.GUID_ContainerFormatPng); // or new PngBitmapEncoder()","handlingStrategy":"validation","validationCode":"if (containerFormat == Guid.Empty)\n    throw new ArgumentException(\"containerFormat must be a non-empty container format GUID\", nameof(containerFormat));\nvar encoder = BitmapEncoder.Create(containerFormat);","typeGuard":"static bool IsValidContainerFormat(Guid g) => g != Guid.Empty;","tryCatchPattern":null,"preventionTips":["Use static readonly Guid constants (GUID_ContainerFormat*) rather than inline construction","Prefer concrete encoder classes (PngBitmapEncoder, etc.) over Guid-based Create","Validate GUIDs parsed from config before use","Never use Guid.Empty as a sentinel that can reach encoder APIs"],"tags":["wpf","guid","argument-validation","imaging"],"backgroundTag":"missing-required-argument","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}