{"record":{"id":"8c8415dd115ccc16","repo":"EllanJiang/GameFramework","slug":"resource-name-is-invalid","errorCode":null,"errorMessage":"Resource name is invalid.","messagePattern":"Resource name is invalid\\.","errorType":"validation","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Resource/ResourceManager.ResourceName.cs","lineNumber":38,"sourceCode":"        private struct ResourceName : IComparable, IComparable<ResourceName>, IEquatable<ResourceName>\n        {\n            private static readonly Dictionary<ResourceName, string> s_ResourceFullNames = new Dictionary<ResourceName, string>();\n\n            private readonly string m_Name;\n            private readonly string m_Variant;\n            private readonly string m_Extension;\n\n            /// <summary>\n            /// 初始化资源名称的新实例。\n            /// </summary>\n            /// <param name=\"name\">资源名称。</param>\n            /// <param name=\"variant\">变体名称。</param>\n            /// <param name=\"extension\">扩展名称。</param>\n            public ResourceName(string name, string variant, string extension)\n            {\n                if (string.IsNullOrEmpty(name))\n                {\n                    throw new GameFrameworkException(\"Resource name is invalid.\");\n                }\n\n                if (string.IsNullOrEmpty(extension))\n                {\n                    throw new GameFrameworkException(\"Resource extension is invalid.\");\n                }\n\n                m_Name = name;\n                m_Variant = variant;\n                m_Extension = extension;\n            }\n\n            /// <summary>\n            /// 获取资源名称。\n            /// </summary>\n            public string Name\n            {\n                get","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Resource/ResourceManager.ResourceName.cs#L20-L56","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure the name argument is a non-empty, non-null string before constructing ResourceName","Check the upstream code that produces the name (path parsing, config, version list) for empty output","Add a guard that logs/skips entries with empty resource names instead of constructing the struct"],"exampleFix":"// before\nvar name = new ResourceName(rawName, variant, extension);\n// after\nif (string.IsNullOrEmpty(rawName)) { throw new ArgumentException(\"Resource name must be non-empty\"); }\nvar name = new ResourceName(rawName, variant, extension);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(name)) throw new ArgumentException(\"Resource name must be non-empty\", nameof(name));","typeGuard":"bool IsValidResourceName(string name) => !string.IsNullOrEmpty(name);","tryCatchPattern":"try { var rn = new ResourceName(name, variant, ext); } catch (GameFrameworkException ex) { Log.Error($\"Invalid resource name '{name}': {ex.Message}\"); }","preventionTips":["Validate name, variant and extension strings before constructing ResourceName","Never build resource names from raw unvalidated user/config input","Log the source path when parsing names so empties are traceable"],"tags":["csharp","gameframework","resource","argument-validation"],"backgroundTag":"empty-required-field","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}