{"record":{"id":"3c5f812bb32d0f06","repo":"EllanJiang/GameFramework","slug":"object-type-is-invalid-settingmanager","errorCode":null,"errorMessage":"Object type is invalid.","messagePattern":"Object type is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Setting/SettingManager.cs","lineNumber":464,"sourceCode":"            return m_SettingHelper.GetObject<T>(settingName);\n        }\n\n        /// <summary>\n        /// 从指定游戏配置项中读取对象。\n        /// </summary>\n        /// <param name=\"objectType\">要读取对象的类型。</param>\n        /// <param name=\"settingName\">要获取游戏配置项的名称。</param>\n        /// <returns>读取的对象。</returns>\n        public object GetObject(Type objectType, string settingName)\n        {\n            if (m_SettingHelper == null)\n            {\n                throw new GameFrameworkException(\"Setting helper is invalid.\");\n            }\n\n            if (objectType == null)\n            {\n                throw new GameFrameworkException(\"Object type is invalid.\");\n            }\n\n            if (string.IsNullOrEmpty(settingName))\n            {\n                throw new GameFrameworkException(\"Setting name is invalid.\");\n            }\n\n            return m_SettingHelper.GetObject(objectType, settingName);\n        }\n\n        /// <summary>\n        /// 从指定游戏配置项中读取对象。\n        /// </summary>\n        /// <typeparam name=\"T\">要读取对象的类型。</typeparam>\n        /// <param name=\"settingName\">要获取游戏配置项的名称。</param>\n        /// <param name=\"defaultObj\">当指定的游戏配置项不存在时，返回此默认对象。</param>\n        /// <returns>读取的对象。</returns>\n        public T GetObject<T>(string settingName, T defaultObj)","sourceCodeStart":446,"sourceCodeEnd":482,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Setting/SettingManager.cs#L446-L482","documentation":"The non-generic GetObject(Type objectType, string settingName) throws this when the objectType argument is null. The manager needs the target Type to deserialize the stored value and cannot proceed without it. Argument-validation guard.","triggerScenarios":"Calling SettingManager.GetObject(null, settingName), e.g., a Type variable obtained via reflection (Type.GetType) that failed to resolve, or a null generic parameter passed through a wrapper.","commonSituations":"Reflection-based loading where Type.GetType(\"Namespace.Type\") returns null due to missing assembly qualification; plugin/type moved to another assembly after a version upgrade; dynamic type lookup built from config strings.","solutions":["Pass a valid runtime Type (e.g., typeof(AudioConfig)).","If resolving by name, use Type.GetType with assembly-qualified name and assert the result is non-null.","Prefer the generic overload GetObject<T>(settingName) to avoid passing Type explicitly.","Log the type name string when reflection resolution returns null to find the config typo."],"exampleFix":"// before\nType t = Type.GetType(\"GameConfig\"); // null, missing assembly qualification\nvar cfg = m_Setting.GetObject(t, \"GameConfig\");\n// after\nType t = typeof(GameConfig); // or Type.GetType(\"MyGame.GameConfig, Assembly-CSharp\")\nvar cfg = m_Setting.GetObject(t, \"GameConfig\");","handlingStrategy":"type-guard","validationCode":"if (objectType != null && !string.IsNullOrEmpty(settingName))\n{\n    var obj = settingManager.GetObject(objectType, settingName);\n}","typeGuard":"bool IsValidTypeArg(Type t) => t != null; // combine with key check","tryCatchPattern":"try { var obj = mgr.GetObject(type, key); }\ncatch (GameFrameworkException ex) when (ex.Message == \"Object type is invalid.\") { Log.Error($\"Type failed to resolve\"); return null; }","preventionTips":["Prefer typeof(T) or the generic overload over reflection-resolved Types.","When using Type.GetType, use assembly-qualified names and assert non-null.","Validate config strings that map to types at load time.","Avoid caching Type lookups that may return null silently."],"tags":["gameframework","argument-validation","reflection","settings"],"backgroundTag":"null-argument","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"}