dotnet/wpf · warning · ArgumentException

SR.SerializerProviderAlreadyRegistered

Error message

SR.SerializerProviderAlreadyRegistered

What it means

SerializerProvider.RegisterSerializer writes the serializer descriptor to the plugins registry key named '{DisplayName}/{AssemblyName}/{AssemblyVersion}/{WinFXVersion}'. When overwrite is false and that key already exists, it throws ArgumentException (SR.SerializerProviderAlreadyRegistered) with the serializer key as the paramName. This prevents duplicate registrations of the same serializer identity.

Solutions

  1. Call RegisterSerializer with overwrite:true to replace the existing registration
  2. Unregister the serializer (UnregisterSerializer) before re-registering, or ignore the duplicate case
  3. Track registration in app state so it runs once; bump AssemblyVersion for genuinely new serializer versions
  4. Catch ArgumentException from RegisterSerializer and treat 'already registered' as success

Example fix

// before
SerializerProvider.RegisterSerializer(descriptor); // throws on re-run
// after
try { SerializerProvider.RegisterSerializer(descriptor); }
catch (ArgumentException) { /* already registered - safe to ignore */ }
// or: SerializerProvider.RegisterSerializer(descriptor, overwrite: true);
Defensive patterns

Strategy: try-catch

Validate before calling

using Microsoft.Win32;
bool IsRegistered(RegistryKey root, string pluginsPath, SerializerDescriptor d) {
    using var plugins = root.OpenSubKey(pluginsPath);
    var key = $"{d.DisplayName}/{d.AssemblyName}/{d.AssemblyVersion}/{d.WinFXVersion}";
    using var k = plugins?.OpenSubKey(key);
    return k != null;
}

Try / catch

try { SerializerProvider.RegisterSerializer(descriptor); }
catch (ArgumentException) { /* already registered - treat as success or re-register with overwrite:true */ }

Prevention

When it happens

Trigger: Calling SerializerProvider.RegisterSerializer twice for the same descriptor without overwrite=true; an installer running a second time; two serializers sharing identical DisplayName/AssemblyName/AssemblyVersion/WinFXVersion.

Common situations: Re-running a plugin installer; upgrading an assembly without bumping AssemblyVersion while re-registering; application startup code that unconditionally registers a built-in serializer each launch.

Understand the failure class

Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Serialization/SerializerProvider.cs:79

        #endregion

        #region Public Methods

        /// <summary>
        /// Registers the serializer plug-in identified by serializerDescriptor in the registry
        /// </summary>
        public static void RegisterSerializer(SerializerDescriptor serializerDescriptor, bool overwrite)
        {

            ArgumentNullException.ThrowIfNull(serializerDescriptor);

            RegistryKey plugIns = _rootKey.CreateSubKey(_registryPath);
            string serializerKey = $"{serializerDescriptor.DisplayName}/{serializerDescriptor.AssemblyName}/{serializerDescriptor.AssemblyVersion}/{serializerDescriptor.WinFXVersion}";

            if (!overwrite && plugIns.OpenSubKey(serializerKey) != null)
            {
                throw new ArgumentException(SR.SerializerProviderAlreadyRegistered, serializerKey);
            }

            RegistryKey newPlugIn = plugIns.CreateSubKey(serializerKey);
            serializerDescriptor.WriteToRegistryKey(newPlugIn);
            newPlugIn.Close();
        }

        /// <summary>
        /// Un-Registers the serializer plug-in identified by serializerDescriptor in the registry
        /// </summary>
        /// <remarks>
        ///     Removes a previously installed plug-n serialiazer from the registry
        ///
        ///     This method currently requires full trust to run.
        /// </remarks>
        public static void UnregisterSerializer(SerializerDescriptor serializerDescriptor)
        {

View on GitHub (pinned to 81131a70a4)