unoplatform/uno · error · InvalidOperationException
GLCanvasElement.IsGLInitializedProperty is read-only.
Error message
GLCanvasElement.IsGLInitializedProperty is read-only.
What it means
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.
Source
Thrown at src/AddIns/Uno.WinUI.Graphics3DGL/GLCanvasElement.cs:285
internal override SkiaSharp.SKPath? Paint(in PaintingSession session)
{
NativeDispatcher.Main.Enqueue(owner.Render, NativeDispatcherPriority.High);
return base.Paint(session);
}
}
#endif
public static DependencyProperty IsGLInitializedProperty { get; } =
DependencyProperty.Register(
nameof(IsGLInitialized),
typeof(bool?),
typeof(GLCanvasElement),
new PropertyMetadata(null, (PropertyChangedCallback)((dO, _) =>
{
var @this = (GLCanvasElement)dO;
if (!@this._changingGlInitialized)
{
throw new InvalidOperationException($"{nameof(GLCanvasElement)}.{nameof(IsGLInitializedProperty)} is read-only.");
}
// We should have arrived here from set_IsGLInitialized, so we could put this line at the end of the
// setter. Instead, we set it to false here to prevent users from calling SetValue.IsGLInitializedProperty
// _inside_ a call to GLCanvasElement.set_IsGLInitialized. This way, if a user intercepts this
// change (e.g. with SubscribeToPropertyChanged) and attempts to make a nested SetValue call, we still
// explode in their face.
@this._changingGlInitialized = false;
})));
/// <summary>
/// Indicates whether this element was loaded successfully or not, including the OpenGL context creation and setup.
/// 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.
/// The value also becomes false if an exception escapes <see cref="Init"/>, <see cref="RenderOverride"/> or the
/// framebuffer setup, in which case the element stops rendering until it is reloaded.
/// </summary>
public bool? IsGLInitialized
{View on GitHub (pinned to 0418340488)
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.
Example fix
// before element.SetValue(GLCanvasElement.IsGLInitializedProperty, true); // after // IsGLInitialized is set by the framework after GL context creation. // Read-only: observe it instead of writing it. bool ready = element.IsGLInitialized ?? false;
Defensive patterns
Strategy: validation
Validate before calling
// IsGLInitialized is read-only; never call SetValue on it from app code. bool ready = element.IsGLInitialized ?? false;
Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Offscreen framebuffer is not complete
- The framebuffer readback failed with {readbackError} while c
- MediaPlayerPresenterExtension must be initialized with a Med
- Owner must be a SvgImageSource instance.
- ChoosePixelFormat failed
AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13).
Data as JSON: /api/errors/3daa933b691bdefa.
Report an issue: GitHub.