EllanJiang/GameFramework · error · GameFrameworkException

Resource name is invalid.

Error message

Resource name is invalid.

What it means

The ResourceName constructor throws this when the `name` argument is null or an empty string. A resource must always have a non-empty name to be identified by the ResourceManager, so the constructor rejects invalid names immediately rather than producing an unusable ResourceName instance.

Solutions

  1. Ensure the name argument is a non-empty, non-null string before constructing ResourceName
  2. Check the upstream code that produces the name (path parsing, config, version list) for empty output
  3. Add a guard that logs/skips entries with empty resource names instead of constructing the struct

Example fix

// before
var name = new ResourceName(rawName, variant, extension);
// after
if (string.IsNullOrEmpty(rawName)) { throw new ArgumentException("Resource name must be non-empty"); }
var name = new ResourceName(rawName, variant, extension);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(name)) throw new ArgumentException("Resource name must be non-empty", nameof(name));

Type guard

bool IsValidResourceName(string name) => !string.IsNullOrEmpty(name);

Try / catch

try { var rn = new ResourceName(name, variant, ext); } catch (GameFrameworkException ex) { Log.Error($"Invalid resource name '{name}': {ex.Message}"); }

Prevention

When it happens

Trigger: Calling `new ResourceName(null, variant, extension)`, `new ResourceName("", variant, extension)`, or a wrapper API (e.g. resource loading helpers) that passes a name parsed from an empty or malformed path segment.

Common situations: Resource paths parsed with string splitting where the path was empty or had a leading separator; configuration files with a blank resource name; dynamic resource names built from user input or version list data that was truncated.

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 EllanJiang/GameFramework@d0c010b051 (2026-09-15). Data as JSON: /api/errors/8c8415dd115ccc16. Report an issue: GitHub.

Appendix: source

Thrown at GameFramework/Resource/ResourceManager.ResourceName.cs:38

        private struct ResourceName : IComparable, IComparable<ResourceName>, IEquatable<ResourceName>
        {
            private static readonly Dictionary<ResourceName, string> s_ResourceFullNames = new Dictionary<ResourceName, string>();

            private readonly string m_Name;
            private readonly string m_Variant;
            private readonly string m_Extension;

            /// <summary>
            /// 初始化资源名称的新实例。
            /// </summary>
            /// <param name="name">资源名称。</param>
            /// <param name="variant">变体名称。</param>
            /// <param name="extension">扩展名称。</param>
            public ResourceName(string name, string variant, string extension)
            {
                if (string.IsNullOrEmpty(name))
                {
                    throw new GameFrameworkException("Resource name is invalid.");
                }

                if (string.IsNullOrEmpty(extension))
                {
                    throw new GameFrameworkException("Resource extension is invalid.");
                }

                m_Name = name;
                m_Variant = variant;
                m_Extension = extension;
            }

            /// <summary>
            /// 获取资源名称。
            /// </summary>
            public string Name
            {
                get

View on GitHub (pinned to d0c010b051)