{"record":{"id":"dcd50aea3993858a","repo":"EllanJiang/GameFramework","slug":"asset-name-is-invalid","errorCode":null,"errorMessage":"Asset name is invalid.","messagePattern":"Asset name is invalid\\.","errorType":"validation","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Resource/ResourceManager.cs","lineNumber":1452,"sourceCode":"        /// <summary>\n        /// 获取所有加载资源任务的信息。\n        /// </summary>\n        /// <param name=\"results\">所有加载资源任务的信息。</param>\n        public void GetAllLoadAssetInfos(List<TaskInfo> results)\n        {\n            m_ResourceLoader.GetAllLoadAssetInfos(results);\n        }\n\n        /// <summary>\n        /// 检查资源是否存在。\n        /// </summary>\n        /// <param name=\"assetName\">要检查资源的名称。</param>\n        /// <returns>检查资源是否存在的结果。</returns>\n        public HasAssetResult HasAsset(string assetName)\n        {\n            if (string.IsNullOrEmpty(assetName))\n            {\n                throw new GameFrameworkException(\"Asset name is invalid.\");\n            }\n\n            return m_ResourceLoader.HasAsset(assetName);\n        }\n\n        /// <summary>\n        /// 异步加载资源。\n        /// </summary>\n        /// <param name=\"assetName\">要加载资源的名称。</param>\n        /// <param name=\"loadAssetCallbacks\">加载资源回调函数集。</param>\n        public void LoadAsset(string assetName, LoadAssetCallbacks loadAssetCallbacks)\n        {\n            if (string.IsNullOrEmpty(assetName))\n            {\n                throw new GameFrameworkException(\"Asset name is invalid.\");\n            }\n\n            if (loadAssetCallbacks == null)","sourceCodeStart":1434,"sourceCodeEnd":1470,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Resource/ResourceManager.cs#L1434-L1470","documentation":"HasAsset(assetName) checks whether an asset exists in the current resource system. A null or empty assetName cannot identify any asset, so ResourceManager throws this GameFrameworkException as argument validation before delegating to the resource loader.","triggerScenarios":"Calling HasAsset(null) or HasAsset(\"\") — e.g. an asset name field that was never assigned, or a name stripped from a path that turned out empty.","commonSituations":"Building asset names dynamically from config or a clicked item whose key is missing; concatenating path segments where one is empty; deserialized data missing the asset field.","solutions":["Validate the asset name is non-empty before calling HasAsset.","Fix the data source (config row, prefab reference, save data) that yields the empty name.","Return a sensible default (HasAssetResult.NotExist or skip) when the name is empty instead of calling the API."],"exampleFix":"// before\nvar result = resourceManager.HasAsset(assetName); // may be empty\n// after\nif (!string.IsNullOrEmpty(assetName))\n{\n    var result = resourceManager.HasAsset(assetName);\n}","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(assetName)) return HasAssetResult.NotExist;","typeGuard":"static bool IsValidAssetName(string n) => !string.IsNullOrEmpty(n);","tryCatchPattern":"try { var r = rm.HasAsset(name); } catch (GameFrameworkException ex) { Log.Error(ex.Message); return HasAssetResult.NotExist; }","preventionTips":["Validate asset names where they are constructed","Fix empty entries in data tables/config","Log the offending name source when empty"],"tags":["gameframework","asset-name","argument-validation","null-argument"],"backgroundTag":"invalid-argument-value","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}