dotnet/wpf · error · ArgumentException

SR.SerializerProviderDisplayNameNull

Error message

SR.SerializerProviderDisplayNameNull

What it means

SerializerDescriptor.CreateFromFactoryInstance validates every property of the supplied ISerializerFactory and throws ArgumentException (SR.SerializerProviderDisplayNameNull) when factoryInstance.DisplayName is null. A serializer descriptor cannot be created or registered without a display name, since it forms part of the registry key and the serializer metadata exposed to users.

Solutions

  1. Set DisplayName in the custom ISerializerFactory implementation to a non-null string
  2. Validate the factory's properties before calling CreateFromFactoryInstance/RegisterSerializer
  3. Throw ArgumentNullException from the factory constructor if a required name parameter is null so the mistake surfaces early

Example fix

// before
class MySerializerFactory : ISerializerFactory { public string DisplayName => null; ... }
// after
class MySerializerFactory : ISerializerFactory { public string DisplayName => "My Serializer"; ... }
Defensive patterns

Strategy: validation

Validate before calling

if (factory == null) throw new ArgumentNullException(nameof(factory));
if (factory.DisplayName == null) throw new InvalidOperationException("Serializer DisplayName must be set before registration");

Type guard

bool HasDisplayName(ISerializerFactory f) => !string.IsNullOrEmpty(f.DisplayName);

Try / catch

try { SerializerProvider.RegisterSerializer(descriptor); }
catch (ArgumentException ex) when (ex.Message.Contains("DisplayName")) { /* fix factory implementation */ }

Prevention

When it happens

Trigger: Calling SerializerDescriptor.CreateFromFactoryInstance or SerializerProvider.RegisterSerializer with an ISerializerFactory whose DisplayName property returns null.

Common situations: Implementing a custom ISerializerFactory and forgetting to set DisplayName in the class or its constructor; a factory whose DisplayName getter computes a value that resolves to null (e.g. from missing resources or config).

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Serialization/SerializerDescriptor.cs:66

        /// <summary>
        /// Creates a SerializerDescriptor. The interface must be defined in the calling assembly
        /// The WinFX version, and assembly name, and version are initialized by reflecting on the calling assembly
        /// </summary>
        /// <remarks>
        ///     Create a SerializerDescriptor from a ISerializerFactory instance
        ///
        ///     This method currently requires full trust to run.
        /// </remarks>
        public static SerializerDescriptor CreateFromFactoryInstance(
            ISerializerFactory  factoryInstance
            )
        {

            ArgumentNullException.ThrowIfNull(factoryInstance);
            if (factoryInstance.DisplayName == null)
            {
                throw new ArgumentException(SR.SerializerProviderDisplayNameNull);
            }
            if (factoryInstance.ManufacturerName == null)
            {
                throw new ArgumentException(SR.SerializerProviderManufacturerNameNull);
            }
            if (factoryInstance.ManufacturerWebsite == null)
            {
                throw new ArgumentException(SR.SerializerProviderManufacturerWebsiteNull);
            }
            if (factoryInstance.DefaultFileExtension == null)
            {
                throw new ArgumentException(SR.SerializerProviderDefaultFileExtensionNull);
            }

            SerializerDescriptor sd = new SerializerDescriptor
            {
                _displayName = factoryInstance.DisplayName,
                _manufacturerName = factoryInstance.ManufacturerName,

View on GitHub (pinned to 81131a70a4)