VisualStateManager throws generic unhelpful exception when a Setter contains an Invalid Element Name
See original GitHub issueDescribe the bug
Trying to override the NavigationView
style is causing a crash in OnApplyTemplate when we move the VisualStateManager to its proper location.
Steps to reproduce the bug
- https://github.com/michael-hawker/UWPCommunityToolkit/tree/onapplytemplate_crash
- Run Toolkit Sample App
- Open on TabbedCommandBar sample
Expected behavior Not crash or coherent error message.
Version Info
NuGet package version: WinUI 2.6.1
Windows app type:
UWP | Win32 |
---|---|
Yes |
Windows version | Saw the problem? |
---|---|
21H1 (19043) | Yes |
October 2020 Update (19042) | |
May 2020 Update (19041) | |
November 2019 Update (18363) | |
May 2019 Update (18362) | |
October 2018 Update (17763) | |
April 2018 Update (17134) | |
Fall Creators Update (16299) | |
Creators Update (15063) |
Device form factor | Saw the problem? |
---|---|
Desktop | |
Xbox | |
Surface Hub | |
IoT |
Additional context Our template is about 80% the same as the inbox NavigationView, we have another Grid around the whole template, which I realized we hadn’t moved our VSM up into (as the VSM wasn’t firing). When moving the VSM up into the top-level Grid, it crashes. If you remove the VSM, it doesn’t crash (but also doesn’t behave as expected).
Stack Trace:
Exception thrown at 0x00007FFDE1D04ED9 in Microsoft.Toolkit.Uwp.SampleApp.exe: Microsoft C++ exception: winrt::hresult_error at memory location 0x000000FF3DAFB2F0.
> Microsoft.Toolkit.Uwp.UI.Controls.Core.dll!Microsoft.Toolkit.Uwp.UI.Controls.TabbedCommandBar.OnApplyTemplate() Line 49 C#
[Native to Managed Transition]
Windows.UI.Xaml.dll!DirectUI::FrameworkElementGenerated::OnApplyTemplateProtected() Line 1096 C++
Windows.UI.Xaml.dll!DirectUI::FrameworkElement::OnApplyTemplateFromCore(CFrameworkElement * nativeTarget) Line 191 C++
[Inline Frame] Windows.UI.Xaml.dll!CFxCallbacks::FrameworkElement_OnApplyTemplate(CFrameworkElement *) Line 850 C++
Windows.UI.Xaml.dll!CFrameworkElement::InvokeApplyTemplate(unsigned char * bAddedVisuals) Line 1289 C++
Windows.UI.Xaml.dll!CFrameworkElement::MeasureCore(XSIZEF availableSize, XSIZEF & desiredSize) Line 1561 C++
Windows.UI.Xaml.dll!CUIElement::MeasureInternal(XSIZEF availableSize) Line 4121 C++
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 3981 C++
[Inline Frame] Windows.UI.Xaml.dll!CGrid::MeasureCell(CUIElement * const rowHeightTypes, const CellUnitTypes columnWidthTypes, const CellUnitTypes) Line 479 C++
Windows.UI.Xaml.dll!CGrid::MeasureCellsGroup(unsigned int cellsHead, unsigned int cellCount, const float rowSpacing, const float columnSpacing, const bool ignoreColumnDesiredSize, const bool forceRowToInfinity, Jupiter::stack_vector<CellCache,16> & cellCacheVector) Line 359 C++
Windows.UI.Xaml.dll!CGrid::MeasureOverride(XSIZEF availableSize, XSIZEF & desiredSize) Line 1219 C++
Windows.UI.Xaml.dll!CFrameworkElement::MeasureCore(XSIZEF availableSize, XSIZEF & desiredSize) Line 1614 C++
Windows.UI.Xaml.dll!CUIElement::MeasureInternal(XSIZEF availableSize) Line 4121 C++
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 3981 C++
[Inline Frame] Windows.UI.Xaml.dll!UIElement_Measure(CUIElement *) Line 999 C++
Windows.UI.Xaml.dll!DirectUI::UIElement::MeasureImpl(Windows::Foundation::Size availableSize) Line 573 C++
Windows.UI.Xaml.dll!DirectUI::UIElementGenerated::Measure(Windows::Foundation::Size availableSize) Line 4318 C++
Windows.UI.Xaml.dll!DirectUI::Page::MeasureOverride(Windows::Foundation::Size availableSize, Windows::Foundation::Size * pReturnValue) Line 628 C++
Windows.UI.Xaml.dll!DirectUI::FrameworkElementGenerated::MeasureOverrideProtected(Windows::Foundation::Size availableSize, Windows::Foundation::Size * pReturnValue) Line 1056 C++
Windows.UI.Xaml.dll!DirectUI::FrameworkElement::MeasureOverrideFromCore(CFrameworkElement * nativeTarget, float inWidth, float inHeight, float * outWidth, float * outHeight) Line 255 C++
[Inline Frame] Windows.UI.Xaml.dll!CFxCallbacks::FrameworkElement_MeasureOverride(CFrameworkElement *) Line 844 C++
Windows.UI.Xaml.dll!CFrameworkElement::MeasureCore(XSIZEF availableSize, XSIZEF & desiredSize) Line 1597 C++
Windows.UI.Xaml.dll!CUIElement::MeasureInternal(XSIZEF availableSize) Line 4121 C++
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 3981 C++
Windows.UI.Xaml.dll!CContentPresenter::MeasureOverride(XSIZEF availableSize, XSIZEF & desiredSize) Line 845 C++
Windows.UI.Xaml.dll!CFrameworkElement::MeasureCore(XSIZEF availableSize, XSIZEF & desiredSize) Line 1614 C++
Windows.UI.Xaml.dll!CUIElement::MeasureInternal(XSIZEF availableSize) Line 4121 C++
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 3981 C++
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031 C++
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031 C++
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031 C++
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031 C++
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031 C++
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031 C++
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031 C++
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031 C++
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031 C++
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031 C++
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031 C++
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031 C++
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031 C++
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031 C++
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031 C++
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031 C++
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031 C++
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031 C++
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031 C++
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031 C++
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031 C++
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031 C++
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031 C++
Windows.UI.Xaml.dll!CUIElement::Measure(XSIZEF availableSize) Line 4031 C++
Windows.UI.Xaml.dll!CLayoutManager::UpdateLayout(unsigned int controlWidth, unsigned int controlHeight) Line 279 C++
[Inline Frame] Windows.UI.Xaml.dll!CLayoutManager::UpdateLayout() Line 226 C++
Windows.UI.Xaml.dll!CUIElement::UpdateLayout() Line 3729 C++
Windows.UI.Xaml.dll!CUIElement::BoundsTestEntry<XPOINTF>(const HitTestParams & hitTestParams, const XPOINTF & target, CBoundedHitTestVisitor * pCallback, bool canHitDisabledElements, bool canHitInvisibleElements) Line 15243 C++
Windows.UI.Xaml.dll!CUIElement::HitTestEntry(const HitTestParams & hitTestParams, XPOINTF hitPoint, bool canHitMultipleElements, bool canHitDisabledElements, bool canHitInvisibleElements, CHitTestResults * pHitElements) Line 2456 C++
Windows.UI.Xaml.dll!CUIElement::HitTestEntry(const HitTestParams & hitTestParams, XPOINTF hitPoint, bool canHitDisabledElements, bool ppHitElement, CUIElement * *) Line 2430 C++
Windows.UI.Xaml.dll!CCoreServices::HitTest(XPOINTF ptHit, CDependencyObject * pHitTestRoot, CDependencyObject * * ppVisualHit, bool hitDisabledElement) Line 4646 C++
Windows.UI.Xaml.dll!ContentRootInput::PointerInputProcessor::HitTestHelper(XPOINTF ptHit, CDependencyObject * pHitTestRoot, CDependencyObject * * ppVisualHit) Line 1043 C++
Windows.UI.Xaml.dll!ContentRootInput::PointerInputProcessor::HitTestWithLightDismissAwareness(xref_ptr<CDependencyObject> & contactDO, XPOINTF contactPoint, MessageMap message, PointerInfo * pointerInfo, CDependencyObject * hitTestRoot) Line 1085 C++
Windows.UI.Xaml.dll!ContentRootInput::PointerInputProcessor::ProcessPointerInput(InputMessage * pMsg, int * handled) Line 263 C++
Windows.UI.Xaml.dll!CInputServices::ProcessInput(InputMessage * pMsg, CContentRoot * contentRoot, int * handled) Line 888 C++
Windows.UI.Xaml.dll!CCoreServices::ProcessInput(InputMessage * pMessage, CContentRoot * contentRoot, int * fHandled) Line 992 C++
Windows.UI.Xaml.dll!CXcpBrowserHost::ReplayPreviousPointerUpdate(unsigned int previousPointerUpdateMsgId) Line 1893 C++
Windows.UI.Xaml.dll!CXcpDispatcher::OnWindowMessage(HWND__ * msg, unsigned int wParam, unsigned __int64 lParam, __int64) Line 1178 C++
[Inline Frame] Windows.UI.Xaml.dll!CXcpDispatcher::ProcessMessage(HWND__ *) Line 911 C++
Windows.UI.Xaml.dll!CXcpDispatcher::WindowProc(HWND__ * hwnd, unsigned int msg, unsigned __int64 wParam, __int64 lParam) Line 842 C++
Windows.UI.Xaml.dll!CDeferredInvoke::DispatchQueuedMessage(bool * dispatchedWork, bool * hasMoreWork) Line 301 C++
[Inline Frame] Windows.UI.Xaml.dll!CXcpDispatcher::MessageTimerCallback() Line 1534 C++
Windows.UI.Xaml.dll!CXcpDispatcher::MessageTimerCallbackStatic(void * myUserData) Line 1526 C++
CoreMessaging.dll!00007ffddf1f53db() Unknown
CoreMessaging.dll!00007ffddf21c85b() Unknown
CoreMessaging.dll!00007ffddf1f996b() Unknown
CoreMessaging.dll!00007ffddf1f8e26() Unknown
CoreMessaging.dll!00007ffddf1f7061() Unknown
CoreMessaging.dll!00007ffddf1f6e83() Unknown
user32.dll!00007ffde2d0e858() Unknown
user32.dll!00007ffde2d0e3dc() Unknown
user32.dll!00007ffde2d20bc3() Unknown
ntdll.dll!00007ffde4630c54() Unknown
win32u.dll!00007ffde2401064() Unknown
user32.dll!00007ffde2d0a5c3() Unknown
user32.dll!00007ffde2d0a523() Unknown
Windows.UI.dll!00007ffdd1cba8ae() Unknown
Windows.UI.dll!00007ffdd1cba680() Unknown
Windows.UI.dll!00007ffdd1cba50b() Unknown
Windows.UI.Xaml.dll!CJupiterWindow::RunCoreWindowMessageLoop() Line 1234 C++
[Inline Frame] Windows.UI.Xaml.dll!CJupiterControl::RunMessageLoop() Line 1065 C++
Windows.UI.Xaml.dll!DirectUI::DXamlCore::RunMessageLoop() Line 2463 C++
twinapi.appcore.dll!00007ffddc8a5eca() Unknown
twinapi.appcore.dll!00007ffddc85e65f() Unknown
SHCore.dll!00007ffde42be449() Unknown
kernel32.dll!00007ffde2eb7034() Unknown
ntdll.dll!00007ffde45e2651() Unknown
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Simplifying Visual State Manager with TargetName
Setters collection. With the new TargetName property I am able to reference other elements by its name. Instead of having to repeat the...
Read more >VisualStateManager thrown exception - xaml
1 Answer 1 ; VisualState x:Name="Pressed"> ; Storyboard> ; ObjectAnimationUsingKeyFrames Storyboard.TargetName="RootElement" Storyboard.
Read more >VisualStateManager pitfalls - Martin Zikmund
When the Target or Value of any Setter is invalid, the app will still run without exceptions, but the VisualState containing this Setter...
Read more >Xamarin Community Forums - RSSing.com
"InvalidOperationException: 'this element is not in a namescope'" ... It is only in android that I get this useless page with no information....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We raise a stowed exception that contains a helpful error message, but breaking on those may not be turned on by default in VS. There’s also slightly different behavior in this (and similar) error case depending on whether or not a debugger attached for historical reasons that we really should get rid of. I agree that overall it’s a pretty meh experience.
Yeah, Setter’s will compile even if their targets are not defined, but when they are executed they will have a runtime crash. It would be great if the error message that was raised was more reasonable though. @RealTommyKlein could this error message be improved from the xaml compiler side?
@michael-hawker sounds like you found the cause of your issue, maybe we can rename this issue to be about making the error message for this scenario better?