Skip to content
New issue

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

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

Already on GitHub? # to your account

Managed vtable types (ie. containing any reference types) are not supported. (With WindowsSdkPackageVersion 10.0.19041.38) #2999

Closed
inforithmics opened this issue Sep 15, 2024 · 31 comments
Labels

Comments

@inforithmics
Copy link

inforithmics commented Sep 15, 2024

Description

In this pull request I try to Update the WindowsAppSDK Dependency to 1.6.240829007

Mapsui/Mapsui#2747

This needs following Entry in the csproj File

<!-- Windows App Sdk 1.6 Workaround-->
<WindowsSdkPackageVersion>10.0.19041.38</WindowsSdkPackageVersion>

Which in Turn causes Managed vtable types (ie. containing any reference types) are not supported

What I discovered is that adding alone without Updating WindowsAppSdk Causes this Exception so it is a Behavior change
In the Windows App SDK Ref starting around 10.0.x.38 Versions.

<!-- Windows App Sdk 1.6 Workaround-->
<WindowsSdkPackageVersion>10.0.19041.38</WindowsSdkPackageVersion>

Sample the Reproduces the Crash, should display a circle could not test it it crashed before it can display anything.

From the Callstack it seems Code that is executed in SKXamlCanvas.DoInvalidate crashes the Application

App1.zip

Code

The best way to share code for larger projects is a link to a GitHub repository: https://github.com/user/repo/tree/bug-123

But, you can also share a short block of code here:

// some C# code here

You can also share some XAML:

<!-- xaml code here -->

Expected Behavior

No exception and SkiaSharp Works with WindowsAppSdk 1.6

Actual Behavior

SkiaSharp Crashes with Exception of "Which in Turn causes Managed vtable types (ie. containing any reference types) are not supported"

Version of SkiaSharp

2.88.3 (Current)

Last Known Good Version of SkiaSharp

None

IDE / Editor

Visual Studio (Windows)

Platform / Operating System

Windows

Platform / Operating System Version

Windows 11, Visual Studio 2022 Preview 17.12

Devices

Windows Packaged Windows App

Relevant Screenshots

Call Stack of Exception in the IDE.
image

Relevant Log Output

Call Stack Of Exception


WinRT.Runtime.dll!WinRT.ObjectReference<ABI.SkiaSharp.Views.Windows.IBufferByteAccess.Vftbl>.GetVtable(nint thisPtr)
WinRT.Runtime.dll!WinRT.ObjectReference<ABI.SkiaSharp.Views.Windows.IBufferByteAccess.Vftbl>.ObjectReference(nint thisPtr)
WinRT.Runtime.dll!WinRT.ObjectReference<ABI.SkiaSharp.Views.Windows.IBufferByteAccess.Vftbl>.Attach(ref nint thisPtr, System.Guid iid)
WinRT.Runtime.dll!WinRT.ObjectReference<ABI.SkiaSharp.Views.Windows.IBufferByteAccess.Vftbl>.TryAs(WinRT.IObjectReference sourceRef, System.Guid iid, out WinRT.ObjectReference<ABI.SkiaSharp.Views.Windows.IBufferByteAccess.Vftbl> objRef)
WinRT.Runtime.dll!WinRT.IObjectReference.TryAs<ABI.SkiaSharp.Views.Windows.IBufferByteAccess.Vftbl>(System.Guid iid, out WinRT.ObjectReference<ABI.SkiaSharp.Views.Windows.IBufferByteAccess.Vftbl> objRef)
WinRT.Runtime.dll!WinRT.IObjectReference.As<ABI.SkiaSharp.Views.Windows.IBufferByteAccess.Vftbl>(System.Guid iid)
WinRT.Runtime.dll!WinRT.IObjectReference.As<ABI.SkiaSharp.Views.Windows.IBufferByteAccess.Vftbl>()
[Native to Managed Transition]
[Managed to Native Transition]
System.Private.CoreLib.dll!System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(object obj, nint* args)
System.Private.CoreLib.dll!System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(object obj, System.Reflection.BindingFlags invokeAttr)
WinRT.Runtime.dll!WinRT.IWinRTObject.IsInterfaceImplementedFallback.__GetObjectReferenceViaVftbl|1_1(WinRT.IObjectReference objRef, System.Type vftblType)
WinRT.Runtime.dll!WinRT.IWinRTObject.IsInterfaceImplementedFallback(System.RuntimeTypeHandle interfaceType, bool throwIfNotImplemented)
WinRT.Runtime.dll!WinRT.IWinRTObject.System.Runtime.InteropServices.IDynamicInterfaceCastable.IsInterfaceImplemented(System.RuntimeTypeHandle interfaceType, bool throwIfNotImplemented)
System.Private.CoreLib.dll!System.Runtime.InteropServices.DynamicInterfaceCastableHelpers.IsInterfaceImplemented(System.Runtime.InteropServices.IDynamicInterfaceCastable castable, System.RuntimeType interfaceType, bool throwIfNotImplemented)
[Native to Managed Transition]
[Managed to Native Transition]
WinRT.Runtime.dll!WinRT.CastExtensions.As<SkiaSharp.Views.Windows.IBufferByteAccess>(object value)
SkiaSharp.Views.Windows.dll!SkiaSharp.Views.Windows.Utils.GetByteBuffer(Windows.Storage.Streams.IBuffer buffer)
SkiaSharp.Views.Windows.dll!SkiaSharp.Views.Windows.WindowsExtensions.GetPixels(Microsoft.UI.Xaml.Media.Imaging.WriteableBitmap bitmap)
SkiaSharp.Views.Windows.dll!SkiaSharp.Views.Windows.SKXamlCanvas.CreateBitmap(out SkiaSharp.SKSizeI unscaledSize, out float dpi)
SkiaSharp.Views.Windows.dll!SkiaSharp.Views.Windows.SKXamlCanvas.DoInvalidate()
Microsoft.InteractiveExperiences.Projection.dll!ABI.Microsoft.UI.Dispatching.DispatcherQueueHandler.Do_Abi_Invoke(nint thisPtr)
[Native to Managed Transition]
[Managed to Native Transition]
Microsoft.WinUI.dll!ABI.Microsoft.UI.Xaml.IApplicationStaticsMethods.Start(WinRT.IObjectReference _obj, Microsoft.UI.Xaml.ApplicationInitializationCallback callback)
Microsoft.WinUI.dll!Microsoft.UI.Xaml.Application.Start(Microsoft.UI.Xaml.ApplicationInitializationCallback callback)
Mapsui.Samples.WinUI.dll!Mapsui.Samples.WinUI.Program.Main(string[] args) Line 26


### Code of Conduct

- [X] I agree to follow this project's Code of Conduct
@inforithmics
Copy link
Author

inforithmics commented Sep 15, 2024

Things I tried.

  1. Update to .NET 9 no success
  2. Update SkiaSharp to 3 Preview no success
  3. Update WindowsSdkPackageVersion to 10.0.19041.45 no success

The only thing that helped was removing
<WindowsSdkPackageVersion>10.0.19041.45</WindowsSdkPackageVersion>
And going back to Version 1.5 of Windows AppSdk.

Because with .NET 8.0.402 the WindowsSdkPackageVersion is updated to something that works with Windows AppSDK 1.6 This error could become quite common. Affecting Maui, Uno (WinUI Target), WinUI

Or is this a Bug in the WindowsAppSDK itself?

The Problem seems to be here, in The GetPixels function.
https://github.com/mono/SkiaSharp/blob/main/source/SkiaSharp.Views/SkiaSharp.Views.WinUI/UWPExtensions.cs#L180

Could this be fixed by this Commit 9fde53e
Seems not to be included in the latest SkiaSharp 3.0 Preview (Which is from 17.July and this commit is from the 18. July)

@inforithmics
Copy link
Author

I managed to Compile SkiaSharp locally and confirm that it works now, so this Bug was indeed fixed, But needs a SkiaSharp nuget Release.

@jeromelaban
Copy link
Contributor

jeromelaban commented Sep 23, 2024

@mattleibow This fix would also need to be backported to 2.x, ideally. Thanks!

@inforithmics
Copy link
Author

inforithmics commented Sep 23, 2024

#2920

I think this pull request needs to be back ported

@inforithmics
Copy link
Author

microsoft/CsWinRT#1645

And this is the issue

@Auto72
Copy link

Auto72 commented Sep 26, 2024

I made an App in ,NET MAUI (8.0.91) that communicate with my BLE device and uses SkiaSharp and it works very well on Android and iOS. When I try to run it on Windows, and SkiaSharp get involved, it crashes and Visual Studio shows the dialog to select a debugger.

I use the following NuGet packages:

SkiaSharp.Views.Maui.Controls ver. 3.0.0-preview.4.1
SkiaSharp.Views.Maui.Controls.Compatibility ver. 2.88.8
SkiaSharp.Views.Maui.Core ver. 3.0.0-preview.4.1
CommunityToolkit.Mvvm ver. 8.3.2 (just to use ObservableObject)

In order to use CommunityToolkit.Mvvm ver. 8.3.2, I put the following tag to the project file:
< WindowsSdkPackageVersion >10.0.19041.45 < /WindowsSdkPackageVersion >

CommunityToolkit/dotnet#951

Here the errors Log:

2024-09-26 17:42:34.972 [MauiUnhandledExceptionManager] FirstChanceException caught: Managed vtable types (ie. containing any reference types) are not supported.
Exception occurred in method: GetVtable
Class: WinRT.ObjectReference`1
File: Line: 0

2024-09-26 17:42:34.974 [MauiUnhandledExceptionManager]
FirstChanceException
Managed vtable types (ie. containing any reference types) are not supported.
(StackTrace)
at WinRT.ObjectReference`1.GetVtable(IntPtr thisPtr)

2024-09-26 17:42:34.975 [MauiUnhandledExceptionManager] FirstChanceException caught: Exception has been thrown by the target of an invocation.
Exception occurred in method: InvokeWithNoArgs
Class: System.Reflection.MethodBaseInvoker
File: Line: 0

2024-09-26 17:42:34.976 [MauiUnhandledExceptionManager]
FirstChanceException
Exception has been thrown by the target of an invocation.
(StackTrace)
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

The program '[21316] MYAPPNAME.exe: Program Trace' has exited with code 0 (0x0).
The program '[21316] MYAPPNAME.exe' has exited with code 3221226107 (0xc000027b).

@Bush-cat
Copy link

@Auto72 to fix your issue either use winappsdk 10.0.19041.34 (anything lower than .38) or get the patched update from their azure build servers (there is no nuget release yet)

@Auto72
Copy link

Auto72 commented Sep 27, 2024

@Bush-cat I used the winappsdk 10.0.19041.34 and I reverted to use the NuGet library CommunityToolkit.Mvvm ver 8.2.2 and now my App works also on Windows.
Thanks a lot 👍

@mattleibow
Copy link
Contributor

Can you try the latest nightly on https://aka.ms/skiasharp-eap/index.json and let me know if it starts working again? I want to do a release, but I want to make sure I fixed it.

@Auto72
Copy link

Auto72 commented Sep 30, 2024

@mattleibow I tried my app using the latest nightly build of SkiaSharp on Windows:

SkiaSharp.Views.Maui.Controls ver. 3.0.0-preview.5.3
SkiaSharp.Views.Maui.Controls.Compatibility ver. 3.0.0-alpha.1.2
SkiaSharp.Views.Maui.Core ver. 3.0.0-preview.5.3

I also used the NuGet library

CommunityToolkit.Mvvm ver. 8.3.2

And in the project file I added:
< WindowsSdkPackageVersion >10.0.19041.45 < /WindowsSdkPackageVersion >

and now it works 🥳🥳🥳

@jeromelaban
Copy link
Contributor

@mattleibow I can also confirm that 3.0.0-preview.5.3 is working on WinAppSDK 1.6.

@inforithmics
Copy link
Author

inforithmics commented Sep 30, 2024

@mattleibow, Yes I can confirm that it works now. (SkiaSharp.Views.WinUI 3.0.0 on WindoAppSDK 1.6)

@beto-rodriguez
Copy link
Contributor

3.0.0-preview.5.3 works!

@bytesandwich
Copy link

3.0.0-preview.5.3 works for me too.

@mpulukkinen
Copy link

I've been fighting with this issue for whole evening now. I don't even know how this happened to me. I was implementing some Microsoft Store features and suddenly my app started crashing. Yesterday everything worked fine. Stashing all changes and clean build and stuff does not help. Also the workarounds mentioned above do not help. DId I get some secret update that I'm not aware or did my windows update?

@bfmyr4
Copy link

bfmyr4 commented Oct 10, 2024

I've been fighting with this issue for whole evening now. I don't even know how this happened to me. I was implementing some Microsoft Store features and suddenly my app started crashing. Yesterday everything worked fine. Stashing all changes and clean build and stuff does not help. Also the workarounds mentioned above do not help. DId I get some secret update that I'm not aware or did my windows update?

This is in the release notes for 17.11.5: "Updated the Windows 11 SDK (10.0.26100.0) installed by Visual Studio to the October 2024 servicing build."

I was able to workaround this by adding this to my .csproj:
<WindowsSdkPackageVersion>10.0.19041.34</WindowsSdkPackageVersion>

@mpulukkinen
Copy link

Ah, thank you very much, that worked. At least I won't waste another evening with this

@TopperDEL
Copy link

TopperDEL commented Oct 11, 2024

3.0.0-preview.5.3 resolves my issue!

Temporarily adding this to my csproj works, too:

<WindowsSdkPackageVersion>10.0.19041.34</WindowsSdkPackageVersion>

@Joost-Jens-Luminis
Copy link

Where can I get the 3.0.0-preview.5.3? It's not on the nuget servers which only go until 4.1.

Can I only get that from the nightly build server?

Furhter more, is there a release timeline for version 3.0? If that is far away, will this be backported?

@TopperDEL
Copy link

Where can I get the 3.0.0-preview.5.3? It's not on the nuget servers which only go until 4.1.

You need the nightly builds as nuget-feed: https://aka.ms/skiasharp-eap/index.json

@Joost-Jens-Luminis
Copy link

@TopperDEL Thanks for the quick response. It is much appreciated.
I can also confirm it works with that build.

@eysdev
Copy link

eysdev commented Oct 11, 2024

It works :)

@core2lord
Copy link

While on VS2022 version '17.11.5', is it correct that I'm to keep the 'LiveChartsCore.SkiaSharpView.WinUI'[2.0.0-rc3.3]
and add
'SkiaSharp.Views.WInUI'[3.0.0-preview.5.3]

After doing so, when trying to run my app or the LiveCharts WinUI sample app, I receive a different error
"Could not load type 'CropRect' from assembly 'SkiaSharp, Version=3.0.0.0".

Also, when adding the following to the csproj file
<WindowsSdkPackageVersion>10.0.19041.34</WindowsSdkPackageVersion>
I receive an error
minimum required SDK is '10.0.19041.38'
but dropping down to NuGet SDK version '1.5.241001000' from '1.6.240923002' did rid of this message.

@beto-rodriguez
Copy link
Contributor

@core2lord Because the latest version of LiveCharts is not running on SkiaSharp 3, you need to build #1622 to fix that.

@core2lord
Copy link

@beto-rodriguez wow, you are on top of it thank you for such quick reply. I've
cloned the repository then tried right clicking the VS2022 WinUI project -> selecting 'Pack'. Tried the different build configs ad-hoc, release, appstore, with x64 and x86, along with making the SDK, SDK builder, SkiaSharp versions matched exactly as you have shown in the #1622 commit. I've also tried running the PS scripts inside the build folder to no avail. I continue to get build errors for metadata files missing and/or unable to sign a file, etc...I will just hang my head low in embarrassment and say that I have been trying to do this since I read your comment 32 minutes after you posted it, but I don't think I'm approaching this correctly at all :/

@Bush-cat
Copy link

@core2lord you just cloned the master repo and updated the skiasharp dependency?
You're missing commits then, you will need this branch
https://github.com/beto-rodriguez/LiveCharts2/tree/skiasharp-3

@Joost-Jens-Luminis
Copy link

Is there any idea on when this will be released?
The Azure DevOps pipeline (which we are using) is now updated that it requires this fix be in place. So no we are stuck between using a nightly build version of this package, or downgrading our pipeline and not updating to the latest WIndowsAppSDK.

This will also be a problem when updating to .Net 9 later this year.

@AdrianSkib
Copy link

This issue has broken my MapsUI application on windows 11. Hope this fix is released soon.

I tried with the pre-release, but it doesn't seem to be completely ready yet, as it just led to other errors.

@ghuotvez
Copy link

This issue has broken my MapsUI application on windows 11. Hope this fix is released soon.

I tried with the pre-release, but it doesn't seem to be completely ready yet, as it just led to other errors.

Same it broke my mapsui.

@mattleibow
Copy link
Contributor

I pushed out a new version of SkiaSharp which should have all the WASDK fixes in it.

@mattleibow
Copy link
Contributor

Closing this for now as the issue is fixed for both v2 and v3 in the latest preview.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests