WindowsCommunityToolkit icon indicating copy to clipboard operation
WindowsCommunityToolkit copied to clipboard

AttachedCardShadow crashes side-loaded packaged WinUI 3 app

Open wbokkers opened this issue 2 years ago • 12 comments

Describe the bug

When using AttachedCardShadow anywhere in my app (WinUI3 / WinAppSDK 1.0), it runs fine from Visual Studio. But as soon as I package the app and run it, the app crashes. I get the following stack trace: image

The exception message is: "System.Runtime.InteropServices.COMException: Class not registered (0x80040154 (REGDB_E_CLASSNOTREG))"

Steps to Reproduce

Unfortunately I can't reproduce this in a sample app that starts with the newest templates. My app was converted from one of the earliest ProjectReunion version to all subsequent versions until the current Windows App SDK 1.0 release. I can't find major/important differences in the project files (csproj and wapproj), though. Steps to reproduce the behavior:

  1. Use AttachedCardShadow anywhere in the app.
  2. Sign manifest
  3. Package using: Publish | Create App Packages...
  4. Install by running the Add-AppDevPackage.ps1
  5. Run

Expected behavior

The app should run without a crash

Screenshots

Environment

image image

NuGet Package(s):

Package Version(s):

Windows 10 Build Number: 21H2 / 19044.1348

App min and target version: Min: April 2018 Update (17134) Target: May 2020 Update (19041)

Device form factor: Desktop

Visual Studio version: 2022 (17.0.1)

wbokkers avatar Dec 01 '21 08:12 wbokkers

Hello wbokkers, thank you for opening an issue with us!

I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible. Other community members may also look into the issue and provide feedback 🙌

msftbot[bot] avatar Dec 01 '21 08:12 msftbot[bot]

@azchohfi I don't think they had any migration steps for upgrading between WASDK versions, eh? I think the best bet here is to start a new project from the latest templates and copy the project's code over to it and see if it resolves the issue?

This seems like a config/environment issue potentially?

michael-hawker avatar Dec 01 '21 23:12 michael-hawker

This is an activation issue. Which DLL does your app.manifest registers that type in? Is this a clean build? Try deleting bin/obj and rebuilding it.

azchohfi avatar Dec 02 '21 00:12 azchohfi

@azchohfi I tried to delete bin/obj folders and rebuilding again several times. This does not work.

wbokkers avatar Dec 02 '21 11:12 wbokkers

@azchohfi Unfortunately, I don't know what to make of what you're saying about the app.manifest.

wbokkers avatar Dec 02 '21 11:12 wbokkers

Oh, my bad. I looked into this better and it seems like a Win2D issue. @getrou / @iablaauw-MS

azchohfi avatar Dec 02 '21 18:12 azchohfi

@wbokkers could you please try an equivalent of this? https://github.com/microsoft/Win2D/issues/831#issuecomment-909460475

azchohfi avatar Dec 06 '21 19:12 azchohfi

@azchohfi I don't know what the valid equivalent is. If I include the inProcessServer extension, the manifest is invalid.

wbokkers avatar Dec 10 '21 13:12 wbokkers

Any luck with this? I'm having this problem on an unpackaged v1.1.1 WinUI3 app. This was the only WinUI3 shadow I could get working, and of course outside of VS it fails. Any suggestions for alternatives?

appindus-ibiller avatar Jun 22 '22 19:06 appindus-ibiller

@niels9001 I know you've been playing around with shadows lately, and maybe on WinUI 3, have you noticed any issues?

michael-hawker avatar Jun 22 '22 20:06 michael-hawker

@michael-hawker

I have not, I'll give it a try tomorrow to see if I can reproduce this 👍

niels9001 avatar Jun 22 '22 20:06 niels9001

I can confirm that this is still an issue in CommunityToolkit.WinUI.UI 7.1.2

Hopefully there's a fix for this soon as I would like to not have to proceed with DropShadowPanel.

Wandtket avatar Aug 17 '22 16:08 Wandtket

Followed the repro steps mentioned above, and I'm not able to reproduce this.

XAML:

  <Grid>
        <Rectangle
            Width="64"
            Height="64"
            Fill="Red">
            <ui:Effects.Shadow>
                <media:AttachedCardShadow
                    BlurRadius="{Binding ElementName=blurSlider, Path=Value}"
                    Offset="0,4,0"
                    Color="Black" />
            </ui:Effects.Shadow>
        </Rectangle>
    </Grid>

Windows 11 Microsoft.WindowsAppSDK 1.1.5 CommunityToolkit.WinUI 7.1.2

@Wandtket @wbokkers are you on Windows 10?

niels9001 avatar Oct 11 '22 15:10 niels9001

@niels9001 I installed your test app and it worked fine (once I switched to light mode) on my Win 10 (21H2 19044.2006) box:

image

Oh, @niels9001 I just noticed your code above. You're using AttachedDropShadow. This bug is about AttachedCardShadow...

They're two different implementations. Drop shadow uses composition. Card shadow uses Win2D.

Mind updating your test app and seeing if you notice the issue with the other shadow type? Happy to test it out on my Win10 box again if it works on your Win 11 one.

michael-hawker avatar Oct 11 '22 22:10 michael-hawker

Oh, @niels9001 I just noticed your code above. You're using AttachedDropShadow. This bug is about AttachedCardShadow...

Facepalm. I've updated the snippet above. AttachedCardShadow works fine on my machine as well, so no changes there!

niels9001 avatar Oct 12 '22 19:10 niels9001

@niels9001 I can't remember exactly, but I was probably running Windows 10. I was not able to reproduce it with newer templates, but on adding it to my app originally created with older templates, the crash happens. If I find time I will try to AttachedCardShadow again.

wbokkers avatar Oct 12 '22 19:10 wbokkers

@wbokkers could be something changed in the templates or some VS config related to the Windows App SDK.

Going to move this out of our current milestone as we can't reproduce, but let us know if you get a repro with any of the current code for the Windows App SDK and/or toolkit.

michael-hawker avatar Oct 12 '22 22:10 michael-hawker

Still an issue FWIW on 1.1.5 System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.||EXCEPTION OCCURRED: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 Microsoft.Graphics.Canvas.Geometry.CanvasGeometry._ICanvasGeometryStatics..ctor() at System.RuntimeType.CreateInstanceOfT() --- End of inner exception stack trace --- at System.RuntimeType.CreateInstanceOfT() at System.Activator.CreateInstanceT at WinRT.WeakLazy1.get_Value() at Microsoft.Graphics.Canvas.Geometry.CanvasGeometry._ICanvasGeometryStatics.get_Instance() 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.<GetEventInvoke>b__1_0(Object sender, RoutedEventArgs e) at ABI.Microsoft.UI.Xaml.RoutedEventHandler.Do_Abi_Invoke(IntPtr thisPtr, IntPtr sender, IntPtr e) at System.RuntimeType.CreateInstanceOfT() at System.Activator.CreateInstance[T]() at WinRT.WeakLazy1.get_Value() at Microsoft.Graphics.Canvas.Geometry.CanvasGeometry._ICanvasGeometryStatics.get_Instance() 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.<GetEventInvoke>b__1_0(Object sender, RoutedEventArgs e) at ABI.Microsoft.UI.Xaml.RoutedEventHandler.Do_Abi_Invoke(IntPtr thisPtr, IntPtr sender, IntPtr e)

appindus-ibiller avatar Oct 13 '22 17:10 appindus-ibiller

Thanks @appindus-ibiller, we haven't been able to reproduce. Do you happen to have a minimal file->new project with just a shadow added which can trigger this crash?

Can you provide some info about what version of Windows you're on?

michael-hawker avatar Oct 13 '22 23:10 michael-hawker

As I tried to create a minimal project with the crash I almost gave up as I couldn't get it to crash. But for whatever reason, it works on my dev computer. When I load it on one of our kiosk machines it still crashes though. That machine is running 17763.. so I'm guessing that isn't a viable build for at least this stuff. I tested it on a random windows 11 machine and it worked fine too, so it would appear to be that this is a windows version problem. I will try to get that to the next LTSC version (21H2/19044) and see if that solves everything. Thank you for looking into all of this stuff and being so active. I'll update if/when I get that data point.

appindus-ibiller avatar Oct 14 '22 15:10 appindus-ibiller

@appindus-ibiller 17763 is indeed going to be your issue then. I'm surprised it lets you target and install on that, the current Toolkit WinUI package only supports down to 18362. See issue #4603.

@Ryken100 the Win2D type in the stack I imagine is due to Win2D also not supporting down to 17763 at the time, right? Once we fix #4603 I imagine that won't be an issue with WinUI 3 as any types should be lifted?

Though I think for UWP at least, we also have an issue with CompositionVisualSurface as a future culprit here as well, as it is only supported down to 18362.

We have a guard for it that we do for the Mask here:

https://github.com/CommunityToolkit/WindowsCommunityToolkit/blob/0864016ae58e8c73ecfd4d57648926bc850c9ce6/Microsoft.Toolkit.Uwp.UI.Media/Shadows/AttachedCardShadow.cs#L120-L125

But do we need it in these other spots as well?

https://github.com/CommunityToolkit/WindowsCommunityToolkit/blob/0864016ae58e8c73ecfd4d57648926bc850c9ce6/Microsoft.Toolkit.Uwp.UI.Media/Shadows/AttachedCardShadow.cs#L201-L236

https://github.com/CommunityToolkit/WindowsCommunityToolkit/blob/0864016ae58e8c73ecfd4d57648926bc850c9ce6/Microsoft.Toolkit.Uwp.UI.Media/Shadows/AttachedCardShadow.cs#L251-L259

https://github.com/CommunityToolkit/WindowsCommunityToolkit/blob/0864016ae58e8c73ecfd4d57648926bc850c9ce6/Microsoft.Toolkit.Uwp.UI.Media/Shadows/AttachedCardShadow.cs#L310-L329

michael-hawker avatar Oct 14 '22 18:10 michael-hawker

@michael-hawker Update: Loaded Windows 10 IoT Enterprise LTSC version 19044 fresh out of the box and problem still occurs. Seems like it works okay on Home and Pro versions.. so it might not even be the build version causing the problem, it might be IoT/Enterprise? Any idea what the issue could be? I can attach a minimal sample to reproduce (which is literally just add Effects.SetShadow(img, new AttachedCardShadow() { BlurRadius = 60, Opacity = 0.5, Color = Microsoft.UI.Colors.Black }); to any BitmapImage in the UI) but I'm not sure how helpful it would be.

appindus-ibiller avatar Oct 26 '22 12:10 appindus-ibiller

@appindus-ibiller thanks for the additional info. It could be the IoT build, that's not something we really test for (I don't know if we know how to set that environment up to try and reproduce at the moment, unless we could do it in a VM?).

Since you're using WinUI 3 though, all the APIs used here should be abstracted from the OS?

I wonder if you tried to create a sample which just called Microsoft.Graphics.Canvas.Geometry.CanvasGeometry.CreateRoundedRectangle (which seemed to be the failing call) with just the Win2D package reference and see if that worked or not. If that doesn't work, then this would be some issue with the Win2D package and the OS version which would need to be resolved outside the Toolkit.

michael-hawker avatar Oct 27 '22 18:10 michael-hawker

@michael-hawker I called it without issue, not sure if it has to tie in with a UI element or not to get a crash. I'm not really familiar with the Win2D package, only its ability to thwart my progress! If there's a more specific way I need to repro this let me know.

As for the VM, I don't see why it wouldn't be doable. IoT Enterprise is advertised as identical to Enterprise but manages the licenses and distribution differently. I don't have a copy of regular Enterprise to test on, but these versions should be supportable and not behave differently!

appindus-ibiller avatar Oct 28 '22 15:10 appindus-ibiller