stride3d/stride · error · ArgumentException

At least one profile must be specified.

Error message

At least one profile must be specified.

What it means

The YamlSerializerFactoryAttribute constructor requires at least one serializer profile name. It throws ArgumentException when constructed with a null array or an empty params list, because a factory attribute with no profiles could never match any serializer factory.

Solutions

  1. Pass at least one profile name, e.g. [YamlSerializerFactory("Default")]
  2. Use the YamlSerializerFactoryAttribute.Default constant for the standard profile
  3. Remove the attribute entirely if no custom serializer profile is needed

Example fix

// before
[YamlSerializerFactory]
public class MyData {}
// after
[YamlSerializerFactory(YamlSerializerFactoryAttribute.Default)]
public class MyData {}
Defensive patterns

Strategy: validation

Validate before calling

if (profiles == null || profiles.Length == 0) throw new InvalidOperationException("YamlSerializerFactoryAttribute requires at least one profile");

Type guard

null

Try / catch

// Attribute usage is compile-time; caught as runtime ArgumentException only via reflection-based activation
try { var attr = (YamlSerializerFactoryAttribute)Attribute.GetCustomAttribute(t, typeof(YamlSerializerFactoryAttribute)); } catch (ArgumentException ex) { /* report missing profile */ }

Prevention

When it happens

Trigger: Writing [YamlSerializerFactory] (or [YamlSerializerFactory(null)]) on a class without passing any profile string.

Common situations: Refactoring away a profile name but leaving the bare attribute; typo of Default profile constant and removing the argument entirely.

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 stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/21a19179e5b5a415. Report an issue: GitHub.

Appendix: source

Thrown at sources/core/Stride.Core.Yaml/Serialization/YamlSerializerFactoryAttribute.cs:27

{
    /// <summary>
    /// Attribute use to tag a class that is implementing a <see cref="IYamlSerializable"/> or <see cref="IYamlSerializableFactory"/>
    /// and will be used for asset serialization.
    /// </summary>
    [AttributeUsage(AttributeTargets.Class)]
    public class YamlSerializerFactoryAttribute : Attribute
    {
        private readonly string[] profiles;
        /// <summary>
        /// The name of the default profile. Any serializer factory that lacks this attribute will be considered to be part of the default profile.
        /// </summary>
        public const string Default = "Default";

        public YamlSerializerFactoryAttribute(params string[] profiles)
        {
            if (profiles == null || profiles.Length == 0)
            {
                throw new ArgumentException("At least one profile must be specified.");
            }
            this.profiles = profiles;
        }

        public IReadOnlyList<string> Profiles => profiles;

        public bool ContainsProfile(string profile)
        {
            return profiles.Any(x => string.Equals(x, profile, StringComparison.Ordinal));
        }

        /// <summary>
        /// Identifies if two profiles are equal.
        /// </summary>
        /// <param name="profile1">The first profile to compare.</param>
        /// <param name="profile2">The second profile to compare.</param>
        /// <returns>True if profiles are equal, false otherwise.</returns>
        public static bool AreProfilesEqual(string profile1, string profile2)

View on GitHub (pinned to 96fad776d2)