{"record":{"id":"c7e3750f01a774a3","repo":"EllanJiang/GameFramework","slug":"data-row-type-is-invalid","errorCode":null,"errorMessage":"Data row type is invalid.","messagePattern":"Data row type is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/DataTable/DataTableManager.cs","lineNumber":157,"sourceCode":"        /// 是否存在数据表。\n        /// </summary>\n        /// <typeparam name=\"T\">数据表行的类型。</typeparam>\n        /// <returns>是否存在数据表。</returns>\n        public bool HasDataTable<T>() where T : IDataRow\n        {\n            return InternalHasDataTable(new TypeNamePair(typeof(T)));\n        }\n\n        /// <summary>\n        /// 是否存在数据表。\n        /// </summary>\n        /// <param name=\"dataRowType\">数据表行的类型。</param>\n        /// <returns>是否存在数据表。</returns>\n        public bool HasDataTable(Type dataRowType)\n        {\n            if (dataRowType == null)\n            {\n                throw new GameFrameworkException(\"Data row type is invalid.\");\n            }\n\n            if (!typeof(IDataRow).IsAssignableFrom(dataRowType))\n            {\n                throw new GameFrameworkException(Utility.Text.Format(\"Data row type '{0}' is invalid.\", dataRowType.FullName));\n            }\n\n            return InternalHasDataTable(new TypeNamePair(dataRowType));\n        }\n\n        /// <summary>\n        /// 是否存在数据表。\n        /// </summary>\n        /// <typeparam name=\"T\">数据表行的类型。</typeparam>\n        /// <param name=\"name\">数据表名称。</param>\n        /// <returns>是否存在数据表。</returns>\n        public bool HasDataTable<T>(string name) where T : IDataRow\n        {","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/DataTable/DataTableManager.cs#L139-L175","documentation":"HasDataTable(Type) throws this when the dataRowType argument is null. The DataTableManager keys its tables by row type (TypeNamePair), so a null type cannot be looked up and is rejected immediately before any table lookup happens.","triggerScenarios":"Calling dataTableManager.HasDataTable(null) — typically a variable holding a Type that was never assigned, or a GetType()/typeof() expression that resolved to null via reflection.","commonSituations":"Reflection-driven table registration where Activator or config supplies the row type; a field of type Type left uninitialized; refactorings that renamed row classes and broke a string-to-Type lookup returning null.","solutions":["Pass a concrete row type literal, e.g. HasDataTable(typeof(MyDataRow)).","If the type comes from a variable, check it for null before calling (if (dataRowType == null) return false;).","If the type is resolved from a string via reflection, verify the string matches the full class name and that the assembly is loaded.","Wrap in try-catch (GameFrameworkException) if the type source is dynamic and cannot be validated upfront."],"exampleFix":"// before\ndataTableManager.HasDataTable(rowType);\n// after\nif (rowType == null) throw new ArgumentException(\"dataRowType must be a type implementing IDataRow\");\nbool exists = dataTableManager.HasDataTable(rowType);","handlingStrategy":"validation","validationCode":"if (dataRowType == null) throw new ArgumentException(\"dataRowType must not be null\");\ndataTableManager.HasDataTable(dataRowType);","typeGuard":"bool IsValidRowType(Type t) => t != null && typeof(IDataRow).IsAssignableFrom(t);","tryCatchPattern":"try { dataTableManager.HasDataTable(dataRowType); }\ncatch (GameFrameworkException ex) { Log.Error(\"Invalid data row type: {0}\", ex.Message); }","preventionTips":["Always pass typeof(T) literals instead of Type variables when the row type is known at compile time.","Null-check dynamically resolved Types before any DataTableManager call.","Centralize row-type resolution in one helper that validates against IDataRow."],"tags":["csharp","gameframework","datatable","null-argument"],"backgroundTag":"null-argument","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"}