Description
Describe the bug
Using PipelineVisualFactory effects in XAML, such as BlurEffect or GrayscaleEffect from the CommunityToolkit.WinUI.UI.Media library, throws an unhandled exception when application is run on a virtual machine (Hyper-V).
This may cause the application to crash.
Regression
Unknown
Reproducible in sample app?
- This bug can be reproduced in the sample app.
Steps to reproduce
-
In Visual Studio, create a new project using the template "Blank App, Packaged (WinUI 3 in Desktop)".
-
Add the nuget package CommunityToolkit.WinUI.UI.Media to the project.
-
Use the following XAML in MainWindow.xaml:
xmlns:media="using:CommunityToolkit.WinUI.UI.Media"
<StackPanel>
<TextBlock Text="Testing" Margin="10"/>
<media:UIElementExtensions.VisualFactory>
<media:PipelineVisualFactory Source="{media:BackdropSource}">
<media:BlurEffect Amount="2" />
</media:PipelineVisualFactory>
</media:UIElementExtensions.VisualFactory>
</StackPanel>
- For stack trace of the problem, add the following to the App.xaml.cs and include nuget package System.Diagnostics.EventLog:
public App()
{
UnhandledException += OnUnhandledException;
this.InitializeComponent();
}
private void OnUnhandledException(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e)
{
EventLog eventLog = new();
eventLog.Source = "Application Error";
eventLog.WriteEntry(Package.Current.DisplayName + ": Unhandled exception.\n" + e.Exception, EventLogEntryType.Error);
}
-
Package the application into an msix and install the package in a Windows installation running in a Hyper-V VM.
-
Start the application.
-
Check the EventLog in Windows, where the exception will be logged under the Program category.
Expected behavior
Either:
- The effect shall be made to work even when run on a Hyper-V VM
or - The exception shall be handled and the effect creation shall be skipped because the hardware does not support it.
The application shall not crash.
Stack trace for the unhandled exception
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.Runtime.InteropServices.COMException (0x80040154): Class not registered (0x80040154 (REGDB_E_CLASSNOTREG))
at WinRT.BaseActivationFactory..ctor(String typeNamespace, String typeFullName)
at WinRT.ActivationFactory`1..ctor()
at System.RuntimeType.CreateInstanceOfT()
--- End of inner exception stack trace ---
at System.RuntimeType.CreateInstanceOfT()
at System.Activator.CreateInstance[T]()
at WinRT.WeakLazy`1.get_Value()
at WinRT.ActivationFactory`1.ActivateInstance[I]()
at Microsoft.Graphics.Canvas.Effects.GaussianBlurEffect..ctor()
at CommunityToolkit.WinUI.UI.Media.Pipelines.PipelineBuilder.<>c__DisplayClass12_0.<<Blur>g__Factory|0>d.MoveNext()
--- End of stack trace from previous location ---
at CommunityToolkit.WinUI.UI.Media.Pipelines.PipelineBuilder.BuildAsync()
at CommunityToolkit.WinUI.UI.Media.PipelineVisualFactoryBase.GetAttachedVisualAsync(UIElement element)
at CommunityToolkit.WinUI.UI.Media.PipelineVisualFactory.GetAttachedVisualAsync(UIElement element)
at CommunityToolkit.WinUI.UI.Media.UIElementExtensions.<>c__DisplayClass3_0.<<OnVisualFactoryPropertyChanged>g__Set|0>d.MoveNext()
--- End of stack trace from previous location ---
at CommunityToolkit.WinUI.UI.Media.UIElementExtensions.<>c__DisplayClass3_0.<<OnVisualFactoryPropertyChanged>g__Element_Loaded|1>d.MoveNext()
--- End of stack trace from previous location ---
at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state)
at Microsoft.UI.Dispatching.DispatcherQueueSynchronizationContext.<>c__DisplayClass2_0.<Post>b__0()
Windows Build Number
- Windows 10 1809 (Build 17763)
- Windows 10 1903 (Build 18362)
- Windows 10 1909 (Build 18363)
- Windows 10 2004 (Build 19041)
- Windows 10 20H2 (Build 19042)
- Windows 10 21H1 (Build 19043)
- Windows 11 21H2 (Build 22000)
- Other (specify)
Other Windows Build number
Windows 10 22H2 (Build 19045.2006)
App minimum and target SDK version
- Windows 10, version 1809 (Build 17763)
- Windows 10, version 1903 (Build 18362)
- Windows 10, version 1909 (Build 18363)
- Windows 10, version 2004 (Build 19041)
- Other (specify)
Other SDK version
No response
Visual Studio Version
2022
Visual Studio Build Number
17.5.1
Device form factor
Desktop
Nuget packages
CommunityToolkit.WinUI.UI.Media (7.1.2)
Microsoft.Windows.SDK.BuildTools (10.0.22621.755)
Microsoft.WindowsAppSDK (1.2.221109.1)
System.Diagnostics.EventLog (7.0.0)
Additional context
Application is built as 64-bit and run on a Hyper-V VM under Windows 10 21H2 (19044.2604) on an Intel Core i5-7500T CPU.
Help us help you
No.