dotnet/wpf · error · ArgumentException

Image_GuidEmpty (containerFormat)

Error message

Image_GuidEmpty (containerFormat)

What it means

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.

Solutions

  1. Pass a known container GUID such as MILGuidData.GUID_ContainerFormatPng/Bmp/Jpeg/Tiff/Wmp
  2. Use a concrete encoder type (e.g. new PngBitmapEncoder()) instead of Create
  3. Validate the GUID with Guid.Empty checks before calling Create
  4. Verify the string->Guid conversion used to obtain the format actually succeeded

Example fix

// before
var enc = BitmapEncoder.Create(default(Guid));
// after
var enc = BitmapEncoder.Create(MILGuidData.GUID_ContainerFormatPng); // or new PngBitmapEncoder()
Defensive patterns

Strategy: validation

Validate before calling

if (containerFormat == Guid.Empty)
    throw new ArgumentException("containerFormat must be a non-empty container format GUID", nameof(containerFormat));
var encoder = BitmapEncoder.Create(containerFormat);

Type guard

static bool IsValidContainerFormat(Guid g) => g != Guid.Empty;

Prevention

When it happens

Trigger: Calling BitmapEncoder.Create(Guid.Empty) or passing a default(Guid) (e.g. an uninitialized struct field or failed lookup result) as the container format.

Common situations: 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.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/8b8ef0a23085bee2. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapEncoder.cs:75

        }

        /// <summary>
        /// Internal Constructor.
        /// </summary>
        internal BitmapEncoder(bool isBuiltIn)
        {
            _isBuiltIn = isBuiltIn;
        }

        /// <summary>
        /// Creates a BitmapEncoder from a container format Guid
        /// </summary>
        /// <param name="containerFormat">Container format for the codec</param>
        public static BitmapEncoder Create(Guid containerFormat)
        {
            if (containerFormat == Guid.Empty)
            {
                throw new ArgumentException(
                    SR.Format(SR.Image_GuidEmpty, "containerFormat"),
                    nameof(containerFormat)
                    );
            }
            else if (containerFormat == MILGuidData.GUID_ContainerFormatBmp)
            {
                return new BmpBitmapEncoder();
            }
            else if (containerFormat == MILGuidData.GUID_ContainerFormatGif)
            {
                return new GifBitmapEncoder();
            }
            else if (containerFormat == MILGuidData.GUID_ContainerFormatJpeg)
            {
                return new JpegBitmapEncoder();
            }
            else if (containerFormat == MILGuidData.GUID_ContainerFormatPng)
            {

View on GitHub (pinned to 81131a70a4)