{"record":{"id":"3c64bb7677970b52","repo":"dotnet/maui","slug":"call-to-setbinding-typeof-tsource-typeof-tpro-3c64bb","errorCode":null,"errorMessage":"Call to SetBinding<{typeof(TSource)}, {typeof(TProperty)}> was not intercepted.","messagePattern":"Call to SetBinding<(.+?), (.+?)> was not intercepted\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Core/BindableObjectExtensions.cs","lineNumber":153,"sourceCode":"\t\t/// <exception cref=\"ArgumentNullException\"></exception>\n\t\tpublic static void SetBinding<TSource, TProperty>(\n\t\t\tthis BindableObject self,\n\t\t\tBindableProperty targetProperty,\n\t\t\tFunc<TSource, TProperty> getter,\n\t\t\tBindingMode mode = BindingMode.Default,\n\t\t\tIValueConverter? converter = null,\n\t\t\tobject? converterParameter = null,\n\t\t\tstring? stringFormat = null,\n\t\t\tobject? source = null,\n\t\t\tobject? fallbackValue = null,\n\t\t\tobject? targetNullValue = null)\n\t\t{\n\t\t\tif (!RuntimeFeature.AreBindingInterceptorsSupported)\n\t\t\t{\n\t\t\t\tthrow new InvalidOperationException($\"Call to SetBinding<{typeof(TSource)}, {typeof(TProperty)}> could not be intercepted because the feature has been disabled. Consider removing the DisableMauiAnalyzers property from your project file or set the _MauiBindingInterceptorsSupport property to true instead.\");\n\t\t\t}\n\n\t\t\tthrow new InvalidOperationException($\"Call to SetBinding<{typeof(TSource)}, {typeof(TProperty)}> was not intercepted.\");\n\t\t}\n#nullable disable\n\n\t\tpublic static T GetPropertyIfSet<T>(this BindableObject bindableObject, BindableProperty bindableProperty, T returnIfNotSet)\n\t\t{\n\t\t\tif (bindableObject == null)\n\t\t\t\treturn returnIfNotSet;\n\n\t\t\tif (bindableObject.IsSet(bindableProperty))\n\t\t\t\treturn (T)bindableObject.GetValue(bindableProperty);\n\n\t\t\treturn returnIfNotSet;\n\t\t}\n\n\t\tinternal static bool TrySetDynamicThemeColor(\n\t\t\tthis BindableObject bindableObject,\n\t\t\tstring resourceKey,\n\t\t\tBindableProperty bindableProperty,","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/BindableObjectExtensions.cs#L135-L171","documentation":"Thrown by the same typed SetBinding stub, but AFTER the feature switch check passed: AreBindingInterceptorsSupported is true, yet the call was still not rewritten by the source generator. It means the interceptor was enabled in config but never actually executed against this call site, so the stub ran unmodified. This is a build-pipeline defect, not a runtime config mistake.","triggerScenarios":"Using the lambda SetBinding/Create overload inside a project type the MAUI source generator does not target (e.g. a plain netstandard library, a unit test assembly, or a multi-targeting config where the generator assembly isn't loaded); the lambda expression shape is one the interceptor can't pattern-match (e.g. a block-bodied lambda or one capturing locals); an SDK mismatch where the generator package version differs from the runtime.","commonSituations":"Calling SetBinding with a lambda from a shared library that is not a MAUI app project; upgrading only part of the MAUI packages so the generator and runtime are out of sync; using block-bodied lambdas or method-group conversions instead of expression-bodied getters; incremental-build cache holding a stale generation.","solutions":["Rebuild cleanly (delete obj/bin) so the source generator runs against the current call site.","Ensure the calling project is a MAUI app/library (uses Microsoft.Maui.Controls.Sdk) and not a generic library that lacks the generator reference.","Simplify the getter to a single expression-bodied lambda with no captured locals, e.g. static vm => vm.Title.","Verify Microsoft.Maui.Controls and the source-generator package are the same version.","If the call site can't be intercepted, switch to the string-path Binding overload."],"exampleFix":"// before (block-bodied / capturing lambda - not interceptable)\nmyLabel.SetBinding(Label.TextProperty, vm => { return vm.Title ?? \"-\"; });\n\n// after (expression-bodied, interceptable)\nmyLabel.SetBinding(Label.TextProperty, static vm => vm.Title);","handlingStrategy":"validation","validationCode":"// Before relying on the typed overload, confirm the generator ran by checking the\n// compiled assembly for the generated interceptor method via reflection at test time.\n// At the call site, keep lambdas expression-bodied and static:\nlabel.SetBinding(Label.TextProperty, static vm => vm.Title);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use only expression-bodied static lambdas as getters.","Reference the same Microsoft.Maui.Controls version for runtime and source generator.","Run a clean build after touching binding call sites so the interceptor re-runs."],"tags":["maui","data-binding","source-generators","lambda","interceptor"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}