SkiaSharp icon indicating copy to clipboard operation
SkiaSharp copied to clipboard

[BUG] An ExecutionEngineException is thrown when an SKGLView is assigned to ContentView.Content

Open pauldendulk opened this issue 7 months ago • 5 comments

Description

When a class that is inherited from ContentView assigns an SKGLView to it's Content field this results in a ExecutionEngineException with the message "Exception of type 'System.ExecutionEngineException' was thrown.", there is no stack trace and the application shuts down.

It only occurs when creating a MAUI 9 project. Not when creating a MAUI 8 project.

Using SkiaSharp 3.116.1.

Steps to reproduce:

  • Create a default MAUI 9 template (with everything updated to the latest to date).
  • Add SkiaSharp reference
  • Add the UseSkiaSharp in MauiProgram
  • Create a class like the 'MapControl' below
  • Assign that class to the MainWindow Content
  • The application will crash.

Code

Here is a minimal sample to reproduce it:

https://github.com/pauldendulk/skiasharpcrash

Some snippets from that repo:

using SkiaSharp.Views.Maui.Controls;

namespace MauiApp1;

public class MapControl : ContentView
{
    public MapControl()
    {
        Content = new SKGLView();
    }
}
var mapControl = new MapControl();
Content = mapControl;

Expected Behavior

No crash

Actual Behavior

An ExecutionEngineException with the message "Exception of type 'System.ExecutionEngineException' was thrown." and the application shuts down.

Version of SkiaSharp

3.116.0 (Current)

Last Known Good Version of SkiaSharp

I did not test this.

IDE / Editor

Visual Studio (Windows)

Platform / Operating System

Windows

Platform / Operating System Version

Windows 11

Devices

Dell laptop

Relevant Screenshots

No response

Relevant Log Output


Code of Conduct

  • [x] I agree to follow this project's Code of Conduct

pauldendulk avatar Apr 13 '25 07:04 pauldendulk

We've found some similar issues:

  • #3113 , similarity score: 83%
  • #2648 , similarity score: 82%

If any of the above are duplicates, please consider closing this issue out and adding additional context in the original issue.

Note: You can give me feedback by 👍 or 👎 this comment.

similar-issues-ai[bot] avatar Apr 13 '25 07:04 similar-issues-ai[bot]

We've found some similar issues:

This one is similar, maybe the same problem at heart, but in my bug report we don't need to do anything special with package mode. It is just a default template adding an SKGLView.

This one is different. It simply does not call UseSkiaSharp

pauldendulk avatar Apr 13 '25 07:04 pauldendulk

This is probably the same issue: https://github.com/mono/SkiaSharp/issues/2968

pauldendulk avatar Apr 14 '25 05:04 pauldendulk

If you are going to release your app in Microsoft Store only, you can fix this error by setting WindowsPackageType to MSIX, and creating a launch profile with commandName MsixPackage. This will create a packaged app (MSIX).

TommiGustafsson-HMP avatar Apr 14 '25 12:04 TommiGustafsson-HMP