Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WinRT class throws InvalidCastException on Desktop #779

Closed
getrou opened this issue Mar 25, 2021 · 3 comments
Closed

WinRT class throws InvalidCastException on Desktop #779

getrou opened this issue Mar 25, 2021 · 3 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@getrou
Copy link
Member

getrou commented Mar 25, 2021

In porting a library to WinUI3, a class started throwing an InvalidCastException.
It appears to fail trying to QI the class to an IDependencyObject.
This QI succeeds when done from a UAP but fails in a Desktop packaged app.

Version Info
CsWinRT 1.1.4
.NET SDK 10.0.19041.15
ProjectReunion.0.5.0-prerelease

@getrou getrou added the bug Something isn't working label Mar 25, 2021
@getrou getrou changed the title Win2D's CanvasBitmap throws InvalidCastException WinRT class throws InvalidCastException on Desktop Mar 26, 2021
@angelazhangmsft
Copy link
Contributor

@getrou - Are you authoring a C#/WinRT component? I assume you are creating a C#/.NET5 class library, and consuming it in a C# desktop packaged app (Project Reunion)?

Would you be able to provide a repro?

@sutm
Copy link

sutm commented Apr 24, 2021

I too am encountering invalid cast exception when porting to WinUI3 for a desktop application.
The following line causes the exception to be thrown:
var bitmap = new CanvasRenderTarget(canvasdevice, 16, 16, 96);

Stack trace:
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
at WinRT.IObjectReference.As[T](Guid iid)
at WinRT.IObjectReference.As(Guid iid)
at Microsoft.UI.Xaml.DependencyObject..ctor(IObjectReference objRef)
at Microsoft.Graphics.Canvas.CanvasBitmap..ctor(IObjectReference objRef)
at Microsoft.Graphics.Canvas.CanvasRenderTarget..ctor(IObjectReference objRef)
at Microsoft.Graphics.Canvas.CanvasRenderTarget..ctor(ICanvasResourceCreator resourceCreator, Single width, Single height, Single dpi)

Microsoft.Graphics.Win2D v0.5.0.13
Microsoft. ProjectReunion v0.5.5
Microsoft.Windows.csWinRT v1.2.5

@getrou
Copy link
Member Author

getrou commented Apr 30, 2021

Updating, this was a WRL issue and not a cswinrt issue. I will publish an update to Win2D with a fix next week.

@getrou getrou closed this as completed Apr 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants