{"record":{"id":"7d532673936031e2","repo":"devlooped/moq","slug":"resources-callbasecannotbeusedwithdelegatemocks-mock-1","errorCode":null,"errorMessage":"Resources.CallBaseCannotBeUsedWithDelegateMocks","messagePattern":"Resources\\.CallBaseCannotBeUsedWithDelegateMocks","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Moq/Mock`1.cs","lineNumber":246,"sourceCode":"            }\n        }\n\n        #endregion\n\n        #region Properties\n\n        /// <inheritdoc/>\n        public override MockBehavior Behavior => this.behavior;\n\n        /// <inheritdoc/>\n        public override bool CallBase\n        {\n            get => this.callBase;\n            set\n            {\n                if (value && this.MockedType.IsDelegateType())\n                {\n                    throw new NotSupportedException(Resources.CallBaseCannotBeUsedWithDelegateMocks);\n                }\n\n                this.callBase = value;\n            }\n        }\n\n        internal override object?[] ConstructorArguments => this.constructorArguments;\n\n        internal override Dictionary<Type, object?> ConfiguredDefaultValues => this.configuredDefaultValues;\n\n        /// <summary>\n        /// Gets or sets the <see cref=\"DefaultValueProvider\"/> instance that will be used\n        /// e. g. to produce default return values for unexpected invocations.\n        /// </summary>\n        public override DefaultValueProvider DefaultValueProvider\n        {\n            get => this.defaultValueProvider;\n            set => this.defaultValueProvider = value ?? throw new ArgumentNullException(nameof(value));","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/devlooped/moq/blob/89a5be629c752960fe403e95ff583e4ae6f00542/src/Moq/Mock`1.cs#L228-L264","documentation":"Moq throws this NotSupportedException when CallBase is set to true on a mock whose mocked type is a delegate. CallBase means 'invoke the base class implementation', which is meaningless for delegates since there is no overridable base implementation to call.","triggerScenarios":"new Mock<SomeDelegateType> { CallBase = true } — assigning true to Mock<T>.CallBase (src/Moq/Mock`1.cs:246) when MockedType.IsDelegateType().","commonSituations":"Object-initializer code reused across mock factories that always sets CallBase = true; mocking delegates for HttpClient handlers or callbacks and blindly enabling CallBase.","solutions":["Remove CallBase = true from the delegate mock and define behavior with Setup instead.","If base behavior is genuinely needed, mock the concrete class rather than a delegate.","Only set CallBase conditionally: if (!typeof(T).IsDelegateType()) mock.CallBase = true;"],"exampleFix":"// before\nvar mock = new Mock<EventHandler> { CallBase = true };\n// after\nvar mock = new Mock<EventHandler>();","handlingStrategy":"validation","validationCode":"if (typeof(T).IsSubclassOf(typeof(Delegate)) && enableCallBase)\n    throw new NotSupportedException(\"CallBase is not supported for delegate mocks.\");","typeGuard":"bool CanUseCallBase<T>() => !typeof(T).IsSubclassOf(typeof(Delegate));","tryCatchPattern":"try { mock.CallBase = true; } catch (NotSupportedException) { /* delegate mock: skip CallBase */ }","preventionTips":["Only set CallBase = true for class mocks","Avoid blanket CallBase = true in shared mock-initializer helpers"],"tags":["moq","callbase","delegate","unsupported-operation"],"backgroundTag":"unsupported-operation","analyzedSha":"89a5be629c752960fe403e95ff583e4ae6f00542","analyzedAt":"2026-09-16T05:31:39.496Z","contentChangedAt":"2026-09-16T05:31:39.496Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}