{"record":{"id":"8ac6ec0e30ad98e5","repo":"EllanJiang/GameFramework","slug":"data-row-type-0-is-invalid","errorCode":null,"errorMessage":"Data row type '{0}' is invalid.","messagePattern":"Data row type '(.+?)' is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/DataTable/DataTableManager.cs","lineNumber":162,"sourceCode":"        {\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        {\n            return InternalHasDataTable(new TypeNamePair(typeof(T), name));\n        }\n\n        /// <summary>\n        /// 是否存在数据表。","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/DataTable/DataTableManager.cs#L144-L180","documentation":"HasDataTable(Type) throws this when dataRowType is not null but does not implement the IDataRow interface. DataTableManager only manages tables whose row types implement IDataRow, so any other Type is rejected before the internal lookup.","triggerScenarios":"Calling HasDataTable(typeof(SomeClass)) where SomeClass does not implement IDataRow — e.g. passing a plain data class, a ViewModel, or a row type from an older/incompatible GameFramework version where the interface was named differently.","commonSituations":"Migrating tables from another framework; copy-pasting a data class that forgot the IDataRow interface; passing typeof(DataTableBase) or a generic wrapper type instead of the actual row type.","solutions":["Make the row class implement IDataRow (it must have a public parameterless Id property of type int per the interface contract).","Pass the actual row data type, not a container or base class.","Verify the class implements the IDataRow from the same GameFramework assembly being used at runtime (avoid duplicate interface definitions across assemblies)."],"exampleFix":"// before\npublic class MyDataRow { public int Id { get; set; } }\ndataTableManager.HasDataTable(typeof(MyDataRow));\n// after\npublic class MyDataRow : IDataRow { public int Id { get; set; } }\ndataTableManager.HasDataTable(typeof(MyDataRow));","handlingStrategy":"type-guard","validationCode":"if (dataRowType == null || !typeof(IDataRow).IsAssignableFrom(dataRowType))\n    throw new ArgumentException(\"dataRowType must implement IDataRow: \" + dataRowType?.FullName);","typeGuard":"bool IsValidRowType(Type t) => t != null && typeof(IDataRow).IsAssignableFrom(t);","tryCatchPattern":"try { dataTableManager.HasDataTable(dataRowType); }\ncatch (GameFrameworkException ex) { Log.Error(\"Row type '{0}' does not implement IDataRow.\", dataRowType?.FullName); }","preventionTips":["Make every table row class implement IDataRow as part of your row-class template.","Add a unit test that reflects over all row classes and asserts IDataRow compatibility.","Use generic methods (HasDataTable<T>) so the compiler enforces the constraint where T : class, IDataRow."],"tags":["csharp","gameframework","datatable","type-mismatch"],"backgroundTag":"type-mismatch","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"}