Skip to content

Bug: Passing Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl.Invalidate as the callback argument to a DispatcherQueue.TryEnqueue causes an InvalidCastException in the WinRT runtime #2171

@HeCoding180

Description

@HeCoding180

Description

When trying to directly pass the Invalidate method of a Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl instance as the callback argument of the TryEnqueue method of a DispatcherQueue instance an InvalidCastException is thrown.
When passing a lambda expression that just calls the Invalidate method, the exception is not thrown!

Steps To Reproduce

The following should do the trick (I have not verified this outside of my repo):

DispatcherQueue.TryEnqueue(GraphCanvas.Invalidate);

where GraphCanvas is a Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl instance.
The following code does not throw the exception:

DispatcherQueue.TryEnqueue(() => GraphCanvas.Invalidate());

Expected Behavior

No InvalidCastException is thrown

Version Info

.NET 9.0 Framework

Additional Context

The following image shows one such exception with a stack trace:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions