Skip to content

System.ExecutionEngineException when calling ProcessAsynchronously in WinUI 3 / .NET 10 during debugging #607

@rogago

Description

@rogago

Hello, everyone.
I use C#, WinUI 3, .NET 10 and I encounted a System.ExecutionEngineException when trying to retrive cover art from an audio file using FFMpegCore.

Important detail: The crash happens only when running under the Visual Studio debugger. Launching the application from the Start menu works fine and does not trigger any crash.

Here is a snippet of code from AudioCoverHelper.cs

public static async Task<string?> ExtractCoverPathAsync(string input)
{
    if (string.IsNullOrWhiteSpace(input) || !File.Exists(input))
        return null;

    var hash = Convert.ToHexString(MD5.HashData(Encoding.UTF8.GetBytes(input)))[..16];
    var tempDir = Path.GetTempPath();
    var outPath = Path.Combine(tempDir, $"reform_cover_{hash}.jpg");

    if (File.Exists(outPath) && new FileInfo(outPath).Length >= 128)
        return outPath;

    var ok = await Task.Run(async () =>
    {
        return await FFMpegArguments
            .FromFileInput(input)
            .OutputToFile(outPath, overwrite: true, opt =>
            {
                opt.WithCustomArgument("-an");
                opt.WithCustomArgument("-vcodec copy");
            })
            .ProcessAsynchronously()
            .ConfigureAwait(false);
    }).ConfigureAwait(false);

    return ok && File.Exists(outPath) && new FileInfo(outPath).Length >= 128 ? outPath : null;
}

And also an example of using a helper

var coverPath = await AudioCoverHelper.ExtractCoverPathAsync(_file.FilePath);

if (!string.IsNullOrEmpty(coverPath) && File.Exists(coverPath))
{
    var file = await StorageFile.GetFileFromPathAsync(coverPath);
    using var stream = await file.OpenReadAsync();
    
    var bitmap = new BitmapImage();
    await bitmap.SetSourceAsync(stream);
    
    CoverPreview.ImageSource = bitmap;
}

I think the crash is related to the asynchronous ProcessAsynchronously function with redirected output in the Visual Studio debugger. The problem occurs in both the debug and release x64 builds when running in the debugger. Running the exact same code outside of VS (Start menu) works fine every time.
Has anyone else encountered this behavior? I would greatly appreciate any recommendations for safely using FFMpegCore with WinUI 3 / .NET 10 in the debugger.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions