stride3d/stride · error · ArgumentNullException

Tag prefix must not be empty.

Error message

Tag prefix must not be empty.

What it means

TagDirective's constructor throws ArgumentNullException when the %TAG directive prefix is null or empty. The prefix is the replacement string applied to the handle (a tag URI), and an empty prefix leaves shorthand tags unresolvable, so it is rejected at token construction.

Solutions

  1. Supply a non-empty tag URI after the handle, e.g. `%TAG !e! tag:example.com,2000:`.
  2. Validate `!string.IsNullOrEmpty(prefix)` before constructing TagDirective programmatically.
  3. Remove the %TAG directive entirely if no tag shorthand is needed.

Example fix

// before (YAML)
%TAG !e!
// after (YAML)
%TAG !e! tag:example.com,2000:
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(prefix))
    throw new ArgumentException("%TAG directive requires a non-empty tag URI prefix.");
var token = new TagDirective(handle, prefix, start, end);

Type guard

static bool IsValidTagPrefix(string p) => !string.IsNullOrEmpty(p);

Try / catch

try { return new TagDirective(handle, prefix, start, end); }
catch (ArgumentNullException ex) { throw new YamlSyntaxException($"%TAG directive is missing its tag URI: {ex.Message}", start); }

Prevention

When it happens

Trigger: Parsing a %TAG directive with an empty prefix (e.g. `%TAG !e! ` with nothing after the handle), or constructing TagDirective directly with null/empty prefix.

Common situations: Truncated or hand-edited YAML config files; template expansion that left the tag URI blank; copy-paste of %TAG lines with the URI accidentally deleted.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/c4b0d209a8488ecf. Report an issue: GitHub.

Appendix: source

Thrown at sources/core/Stride.Core.Yaml/Tokens/TagDirective.cs:108

        /// <param name="end">The end position of the token.</param>
        public TagDirective(string handle, string prefix, Mark start, Mark end)
            : base(start, end)
        {
            if (string.IsNullOrEmpty(handle))
            {
                throw new ArgumentNullException("handle", "Tag handle must not be empty.");
            }

            if (!tagHandleValidator.IsMatch(handle))
            {
                throw new ArgumentException("Tag handle must start and end with '!' and contain alphanumerical characters only.", "handle");
            }

            this.handle = handle;

            if (string.IsNullOrEmpty(prefix))
            {
                throw new ArgumentNullException("prefix", "Tag prefix must not be empty.");
            }

            this.prefix = prefix;
        }

        /// <summary>
        /// Determines whether the specified System.Object is equal to the current System.Object.
        /// </summary>
        /// <param name="obj">The System.Object to compare with the current System.Object.</param>
        /// <returns>
        /// true if the specified System.Object is equal to the current System.Object; otherwise, false.
        /// </returns>
        public override bool Equals(object obj)
        {
            TagDirective other = obj as TagDirective;
            return other != null && handle.Equals(other.handle) && prefix.Equals(other.prefix);
        }

View on GitHub (pinned to 96fad776d2)