{"record":{"id":"1a35d67fd4378cc1","repo":"HangfireIO/Hangfire","slug":"unsupported-filter-instance","errorCode":null,"errorMessage":"Unsupported filter instance","messagePattern":"Unsupported filter instance","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Hangfire.Core/Common/JobFilterCollection.cs","lineNumber":143,"sourceCode":"        }\n\n        IEnumerator IEnumerable.GetEnumerator()\n        {\n            return GetEnumerator();\n        }\n\n        // ReSharper disable once UnusedParameter.Local\n        private static void ValidateFilterInstance(object instance)\n        {\n            if (instance != null &&\n                !(instance is IClientFilter \n                || instance is IServerFilter \n                || instance is IClientExceptionFilter \n                || instance is IServerExceptionFilter\n                || instance is IApplyStateFilter\n                || instance is IElectStateFilter))\n            {\n                throw new InvalidOperationException(\"Unsupported filter instance\");\n            }\n        }\n    }\n}","sourceCodeStart":125,"sourceCodeEnd":147,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.Core/Common/JobFilterCollection.cs#L125-L147","documentation":"JobFilterCollection.ValidateFilterInstance (JobFilterCollection.cs:143) guards Add/AddRange calls: only objects implementing at least one Hangfire filter interface (IClientFilter, IServerFilter, IClientExceptionFilter, IServerExceptionFilter, IApplyStateFilter, IElectStateFilter) are accepted. Anything else is rejected because the filter pipeline cannot invoke lifecycle hooks on an incompatible object.","triggerScenarios":"Calling GlobalJobFilters.Filters.Add(someObject) or jobFilterCollection.Add(instance) where instance does not implement any of the six recognized filter interfaces.","commonSituations":"Registering a plain class, a logging middleware, or a third-party attribute that is not a Hangfire filter; accidentally adding a service instance meant for DI; adding an MVC/ASP.NET filter attribute instead of a Hangfire one.","solutions":["Make the class implement the appropriate Hangfire filter interface (IServerFilter for server-side OnPerforming/OnPerformed, IClientFilter for client-side, etc.).","Verify the type implements one of: IClientFilter, IServerFilter, IClientExceptionFilter, IServerExceptionFilter, IApplyStateFilter, IElectStateFilter.","If it is a third-party type, wrap it in an adapter class that implements the correct interface."],"exampleFix":"// before\npublic class RequestLogger { public void Log() { ... } }\nGlobalJobFilters.Filters.Add(new RequestLogger());\n\n// after\npublic class RequestLogger : IServerFilter\n{\n    public void OnPerforming(PerformingContext ctx) { /* log */ }\n    public void OnPerformed(PerformedContext ctx) { }\n}\nGlobalJobFilters.Filters.Add(new RequestLogger());","handlingStrategy":"type-guard","validationCode":"static bool IsHangfireFilter(object instance) =>\n    instance is IClientFilter ||\n    instance is IServerFilter ||\n    instance is IClientExceptionFilter ||\n    instance is IServerExceptionFilter ||\n    instance is IApplyStateFilter ||\n    instance is IElectStateFilter;\n\nif (!IsHangfireFilter(myInstance))\n    throw new InvalidOperationException($\"{myInstance.GetType()} is not a Hangfire filter.\");\nGlobalJobFilters.Filters.Add(myInstance);","typeGuard":"static bool IsHangfireFilter(object instance) =>\n    instance is IClientFilter ||\n    instance is IServerFilter ||\n    instance is IClientExceptionFilter ||\n    instance is IServerExceptionFilter ||\n    instance is IApplyStateFilter ||\n    instance is IElectStateFilter;","tryCatchPattern":null,"preventionTips":["Always implement the correct Hangfire filter interface on classes added to GlobalJobFilters.Filters.","Do not add DI service instances or non-Hangfire attributes to the filter collection.","Use a type check helper before registration when filters come from reflection/plugin loading."],"tags":["filter","interface-validation","registration"],"backgroundTag":null,"analyzedSha":"c236dd0f930f831ec151e436e138ddc429a02a72","analyzedAt":"2026-08-13T20:27:11.027Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}