dotnet/wpf · error · ArgumentException

SR.SerializerProviderDefaultFileExtensionNull

Error message

SR.SerializerProviderDefaultFileExtensionNull

What it means

SerializerDescriptor.CreateFromFactoryInstance throws ArgumentException (SR.SerializerProviderDefaultFileExtensionNull) when the ISerializerFactory's DefaultFileExtension property is null. The default file extension is required to build the SaveFileDialog filter and to associate saved documents with the serializer.

Solutions

  1. Set DefaultFileExtension to a non-null extension (e.g. ".myext") in the factory implementation
  2. Fall back to a default extension when configuration is absent
  3. Pre-validate factory.DefaultFileExtension before calling RegisterSerializer

Example fix

// before
public string DefaultFileExtension => _settings.Extension; // null if not configured
// after
public string DefaultFileExtension => _settings?.Extension ?? ".myext";
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(factory.DefaultFileExtension))
    throw new InvalidOperationException("Serializer DefaultFileExtension must be set before registration");

Type guard

bool HasFileExtension(ISerializerFactory f) => !string.IsNullOrEmpty(f.DefaultFileExtension);

Try / catch

try { SerializerProvider.RegisterSerializer(descriptor); }
catch (ArgumentException) { /* supply DefaultFileExtension and retry */ }

Prevention

When it happens

Trigger: Calling CreateFromFactoryInstance or SerializerProvider.RegisterSerializer with a factory whose DefaultFileExtension returns null.

Common situations: Custom ISerializerFactory implementations forgetting DefaultFileExtension; a factory reading the extension from configuration that is missing.

Related errors


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

Appendix: source

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

            )
        {

            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,
                _manufacturerWebsite = factoryInstance.ManufacturerWebsite,
                _defaultFileExtension = factoryInstance.DefaultFileExtension,

                // When this is called with an instantiated factory object, it must be loadable
                _isLoadable = true
            };

            Type factoryType = factoryInstance.GetType();
            sd._assemblyName = factoryType.Assembly.FullName;
            sd._assemblyPath = factoryType.Assembly.Location;
            sd._assemblyVersion = factoryType.Assembly.GetName().Version;
            sd._factoryInterfaceName = factoryType.FullName;

View on GitHub (pinned to 81131a70a4)