CommunityToolkit / CommunityToolkit/Windows
AttachedCardShadow crashed on .Net 8.0
- Dominant language
- C#
- Stars
- 1.1k
- Forks
- 166
- PR merge metrics
- No merged PRs in 30d
Description
### Describe the bug
We are preparing the upgrade to .Net 8.0 from our .Net 6.0 based project.
Unfortunately the AttachedCardShadow causes a crash with the following exception:
Error message: `The type initializer for 'WinRT.ActivationFactory`1' threw an exception.`
Stacktrace:
` at WinRT.ActivationFactory`1.As(Guid iid)
at Microsoft.Graphics.Canvas.Geometry.CanvasGeometry.Make___objRef_global__Microsoft_Graphics_Canvas_Geometry_ICanvasGeometryStatics()
at Microsoft.Graphics.Canvas.Geometry.CanvasGeometry.get__objRef_global__Microsoft_Graphics_Canvas_Geometry_ICanvasGeometryStatics()
at Microsoft.Graphics.Canvas.Geometry.CanvasGeometry.CreateRoundedRectangle(ICanvasResourceCreator resourceCreator, Single x, Single y, Single w, Single h, Single radiusX, Single radiusY)
at CommunityToolkit.WinUI.UI.Media.AttachedCardShadow.GetShadowClip(AttachedShadowElementContext context)
at CommunityToolkit.WinUI.UI.AttachedShadowBase.UpdateShadowClip(AttachedShadowElementContext context)
at CommunityToolkit.WinUI.UI.AttachedShadowBase.OnElementContextInitialized(AttachedShadowElementContext context)
at CommunityToolkit.WinUI.UI.AttachedShadowElementContext.Initialize(Boolean forceIfNotLoaded)
at CommunityToolkit.WinUI.UI.AttachedShadowElementContext.OnElementLoaded(Object sender, RoutedEventArgs e)
at WinRT._EventSource_global__Microsoft_UI_Xaml_RoutedEventHandler.EventState.b__1_0(Object sender, RoutedEventArgs e)
at ABI.Microsoft.UI.Xaml.RoutedEventHandler.Do_Abi_Invoke(IntPtr thisPtr, IntPtr sender, IntPtr e)
--- End of stack trace from previous location ---
at WinRT.ExceptionHelpers.g__Throw|20_0(Int32 hr)
at ABI.Windows.ApplicationModel.Core.IUnhandledErrorMethods.Propagate(IObjectReference _obj)
at Windows.ApplicationModel.Core.UnhandledError.Propagate()
at Microsoft.AppCenter.Utils.ApplicationLifecycleHelperWinUI.<.ctor>b__0_3(Object sender, UnhandledErrorDetectedEventArgs eventArgs)
--- End of stack trace from previous location ---
at Microsoft.AppCenter.Utils.ApplicationLifecycleHelperWinUI.<.ctor>b__0_3(Object sender, UnhandledErrorDetectedEventArgs eventArgs)
at WinRT.EventSource__EventHandler`1.EventState.b__1_0(Object obj, T e)
at ABI.System.EventHandler`1.Do_Abi_Invoke[TAbi](Void* thisPtr, IntPtr sender, TAbi args)`
There is an innerexception though but it says less:
Message: `Class not registered (0x80040154 (REGDB_E_CLASSNOTREG))`
Stacktrace:
` at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
at WinRT.BaseActivationFactory..ctor(String typeNamespace, String typeFullName)
at WinRT.ActivationFactory`1..ctor()
at WinRT.ActivationFactory`1..cctor()`
A example of how we use it:

We are using version 7.1.2. from the CommunityToolkit.
A quick attempt to upgrade to version 8 didn't resolve the issue either (Same exception).
We are targeting Windows 10.0.19041.0
I am running on Windows 11.
I hope someone can help.
### Steps to reproduce
```text
1. Create a WinUI project in .Net 8.0
2. Add a NavigationView to the page
3. Add an AttachedCardShadow to the Navigation view.
4. Run the program.
```
### Expected behavior
I expect a shadow to be shown and the program to not crash.
### Screenshots
_No response_
### Code Platform
- [ ] UWP
- [X] WinAppSDK / WinUI 3
- [ ] Web Assembly (WASM)
- [ ] Android
- [ ] iOS
- [ ] MacOS
- [ ] Linux / GTK
### 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 10 21H2 (Build 19044)
- [ ] Windows 10 22H2 (Build 19045)
- [X] Windows 11 21H2 (Build 22000)
- [ ] Other (specify)
### Other Windows Build number
_No response_
### App minimum and target SDK version
- [ ] Windows 10, version 1809 (Build 17763)
- [ ] Windows 10, version 1903 (Build 18362)
- [x] Windows 10, version 1909 (Build 18363)
- [ ] Windows 10, version 2004 (Build 19041)
- [ ] Windows 10, version 2104 (Build 20348)
- [ ] Windows 11, version 22H2 (Build 22000)
- [ ] Other (specify)
### Other SDK version
_No response_
### Visual Studio Version
_No response_
### Visual Studio Build Number
_No response_
### Device form factor
_No response_
### Additional context
_No response_
### Help us help you
No, I'm unable to contribute a solution.
Contributor guide
Assessment
This issue has not been assessed yet.