{"record":{"id":"532cd226712b5138","repo":"egametang/ET","slug":"consolehandler-handler-not-inherit-iconsolehandler","errorCode":null,"errorMessage":"ConsoleHandler handler not inherit IConsoleHandler class: {obj.GetType().FullName}","messagePattern":"ConsoleHandler handler not inherit IConsoleHandler class: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"Packages/cn.etetet.console/Scripts/Model/Server/ConsoleDispatcher.cs","lineNumber":31,"sourceCode":"        {\n            HashSet<Type> types = CodeTypes.Instance.GetTypes(typeof (ConsoleHandlerAttribute));\n\n            foreach (Type type in types)\n            {\n                object[] attrs = type.GetCustomAttributes(typeof(ConsoleHandlerAttribute), false);\n                if (attrs.Length == 0)\n                {\n                    continue;\n                }\n\n                ConsoleHandlerAttribute consoleHandlerAttribute = (ConsoleHandlerAttribute)attrs[0];\n\n                object obj = Activator.CreateInstance(type);\n\n                IConsoleHandler iConsoleHandler = obj as IConsoleHandler;\n                if (iConsoleHandler == null)\n                {\n                    throw new Exception($\"ConsoleHandler handler not inherit IConsoleHandler class: {obj.GetType().FullName}\");\n                }\n                this.handlers.Add(consoleHandlerAttribute.Mode, iConsoleHandler);\n            }\n        }\n\n        public IConsoleHandler Get(string key)\n        {\n            return this.handlers[key];\n        }\n    }\n}\n","sourceCodeStart":13,"sourceCodeEnd":43,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.console/Scripts/Model/Server/ConsoleDispatcher.cs#L13-L43","documentation":"Thrown during ConsoleDispatcher initialization when a type decorated with [ConsoleHandler] is instantiated but does not implement the IConsoleHandler interface. The dispatcher casts the created instance via `as IConsoleHandler`; a null result means the contract is not satisfied and the handler cannot be registered.","triggerScenarios":"Applying [ConsoleHandler(...)] to a class that lacks `: IConsoleHandler`; implementing the interface's members without declaring the interface; the interface was renamed/removed during a refactor.","commonSituations":"A developer adds a console command handler class and forgets the interface; refactor splits IConsoleHandler and the type only implements part of it.","solutions":["Make the class implement IConsoleHandler (declare the interface and all its members).","Remove [ConsoleHandler] from the type if it is not actually a handler.","Re-scan so the dispatcher picks up the corrected type."],"exampleFix":"// before\n[ConsoleHandler(\"kick\")]\npublic class KickCommand { /* no interface */ }\n// after\n[ConsoleHandler(\"kick\")]\npublic class KickCommand : IConsoleHandler\n{\n    public void Run(string[] args) { /* ... */ }\n}","handlingStrategy":"type-guard","validationCode":"// in a bootstrap test\nforeach (Type t in CodeTypes.Instance.GetTypes(typeof(ConsoleHandlerAttribute)))\n    Assert.IsTrue(typeof(IConsoleHandler).IsAssignableFrom(t), $\"{t.FullName} must implement IConsoleHandler\");","typeGuard":"static bool IsConsoleHandler(Type t) => typeof(IConsoleHandler).IsAssignableFrom(t);","tryCatchPattern":null,"preventionTips":["Run an assembly-scan test asserting every [ConsoleHandler] implements IConsoleHandler.","Use a code template for command handlers that already declares the interface.","Re-scan after interface refactors."],"tags":["csharp","unity","console","attribute","bootstrap","registration"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}