{"record":{"id":"3daa933b691bdefa","repo":"unoplatform/uno","slug":"glcanvaselement-isglinitializedproperty-is-read-on","errorCode":null,"errorMessage":"GLCanvasElement.IsGLInitializedProperty is read-only.","messagePattern":"GLCanvasElement\\.IsGLInitializedProperty is read-only\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/AddIns/Uno.WinUI.Graphics3DGL/GLCanvasElement.cs","lineNumber":285,"sourceCode":"\t\tinternal override SkiaSharp.SKPath? Paint(in PaintingSession session)\n\t\t{\n\t\t\tNativeDispatcher.Main.Enqueue(owner.Render, NativeDispatcherPriority.High);\n\t\t\treturn base.Paint(session);\n\t\t}\n\t}\n#endif\n\n\tpublic static DependencyProperty IsGLInitializedProperty { get; } =\n\t\tDependencyProperty.Register(\n\t\t\tnameof(IsGLInitialized),\n\t\t\ttypeof(bool?),\n\t\t\ttypeof(GLCanvasElement),\n\t\t\tnew PropertyMetadata(null, (PropertyChangedCallback)((dO, _) =>\n\t\t\t{\n\t\t\t\tvar @this = (GLCanvasElement)dO;\n\t\t\t\tif (!@this._changingGlInitialized)\n\t\t\t\t{\n\t\t\t\t\tthrow new InvalidOperationException($\"{nameof(GLCanvasElement)}.{nameof(IsGLInitializedProperty)} is read-only.\");\n\t\t\t\t}\n\n\t\t\t\t// We should have arrived here from set_IsGLInitialized, so we could put this line at the end of the\n\t\t\t\t// setter. Instead, we set it to false here to prevent users from calling SetValue.IsGLInitializedProperty\n\t\t\t\t// _inside_ a call to GLCanvasElement.set_IsGLInitialized. This way, if a user intercepts this\n\t\t\t\t// change (e.g. with SubscribeToPropertyChanged) and attempts to make a nested SetValue call, we still\n\t\t\t\t// explode in their face.\n\t\t\t\t@this._changingGlInitialized = false;\n\t\t\t})));\n\n\t/// <summary>\n\t/// Indicates whether this element was loaded successfully or not, including the OpenGL context creation and setup.\n\t/// This property is only valid when the element is loaded. When the element is not loaded in the visual tree, the value will be null.\n\t/// The value also becomes false if an exception escapes <see cref=\"Init\"/>, <see cref=\"RenderOverride\"/> or the\n\t/// framebuffer setup, in which case the element stops rendering until it is reloaded.\n\t/// </summary>\n\tpublic bool? IsGLInitialized\n\t{","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/AddIns/Uno.WinUI.Graphics3DGL/GLCanvasElement.cs#L267-L303","documentation":"IsGLInitializedProperty is a read-only dependency property: the framework changes it only via the internal set_IsGLInitialized setter, which sets _changingGlInitialized=true around the SetValue. The property-changed callback throws InvalidOperationException if SetValue is reached while _changingGlInitialized is false — i.e. external code called SetValue(IsGLInitializedProperty, ...) directly, or a nested re-entrant SetValue from a property-changed handler. The throw is intentional to forbid external mutation and re-entrancy.","triggerScenarios":"User code calls element.SetValue(GLCanvasElement.IsGLInitializedProperty, value); or a RegisterDisposablePropertyChangedCallback/OnPropertyChanged handler for IsGLInitialized calls SetValue on the same property, racing past the _changingGlInitialized reset.","commonSituations":"Binding IsGLInitialized two-way from a view-model; calling element.SetValue in a property-changed handler; XAML with a local value set on the read-only property.","solutions":["Treat IsGLInitialized as read-only: never call SetValue on it from app code; read it via the IsGLInitialized getter only.","If you must react to it, subscribe via the property-changed callback for observation only and do NOT re-SetValue the same property.","Remove any two-way binding or local XAML value set on IsGLInitializedProperty."],"exampleFix":"// before\nelement.SetValue(GLCanvasElement.IsGLInitializedProperty, true);\n\n// after\n// IsGLInitialized is set by the framework after GL context creation.\n// Read-only: observe it instead of writing it.\nbool ready = element.IsGLInitialized ?? false;","handlingStrategy":"validation","validationCode":"// IsGLInitialized is read-only; never call SetValue on it from app code.\nbool ready = element.IsGLInitialized ?? false;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat IsGLInitialized as framework-owned; read it, never write it.","Do not bind it two-way or set a local XAML value.","In property-changed handlers, observe only — never re-SetValue the same property."],"tags":["opengl","glcanvaselement","dependencyproperty","readonly","misuse"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}