Skip to content

Access violation in auto generated x:Bind code #2572

Open

Description

Describe the bug
The auto generated x:Bind code triggers an access violation.

Additionally, both TemplateBinding and Binding seems to fail here... TemplateBinding says "Setter does not have a value" (despite that being entirely false) and Binding says "The parameter is incorrect"

Steps to reproduce the bug
Steps to reproduce the behavior:

  1. Clone and run https://github.com/sylveon/xaml-bug-repro
  2. Observe access violation

Expected behavior
No access violation, the app runs successfully and shows the button.

Screenshots
image

Version Info

NuGet package version:
[Microsoft.Windows.CppWinRT 2.0.200514.2]

Windows 10 version Saw the problem?
Insider Build (19041) Yes
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 Yes
Mobile
Xbox
Surface Hub
IoT

Additional context
I found this bug when writing XAML for an XAML Islands application, but it reproduces in UWP.

Activity

  1. added
    needs-triage
    on May 29, 2020
  2. sylveon commented on May 29, 2020

    @sylveon
    ContributorAuthor

    I stepped through the code yesterday, and it seems the issue is this:

    • Connect with id 6 acquires a reference to the ColorAnimation that has its property bound to a value
    • Connect with id 2 updates all values, assuming all other connections where done prior and all references are valid

    For some reason, Connect with id 2 is called but Connect with id 6 never got called prior to that, resulting in the framework trying to access a null pointer

  3. removed
    needs-triage
    on May 29, 2020
  4. sylveon commented on May 29, 2020

    @sylveon
    ContributorAuthor

    Some more updates:

    • This happens in C# as well, both x:Bind and TemplateBinding
    • Binding decided to work in C# and C++ now because ???
  5. sylveon commented on May 29, 2020

    @sylveon
    ContributorAuthor

    Even more updates:

    • Binding was working because I forgot I had changed the Setter for the Normal visual state to use a constant rather than a Binding...
    • If I revert that change in C# and C++ UWP projects it still works, however my XAML Islands project crashes when doing that (and that's my scenario, I don't write UWP)

    Change in question being

                             <VisualState x:Name="Normal">
                                 <VisualState.Setters>
    -                                <Setter Target="ForegroundBrush.Color" Value="White" />
    +                                <Setter Target="ForegroundBrush.Color" Value="{Binding NormalForeground, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=OneWay}" />
                                 </VisualState.Setters>

    (or TemplateBinding or x:Bind)

  6. stevenbrix commented on May 29, 2020

    @stevenbrix
    Contributor

    Adding Evelyn Wu (@evelynwu-msft) who might have an idea of what's going on.

    It looks like the parser isn't calling Connect on the ColorAnimation; is the VisualTransition deferred?

  7. evelynwu-msft commented on May 29, 2020

    @evelynwu-msft
    Member

    Yeah, they're deferred, but I would expect Connect() to be called when the transition is undeferred. Although I wonder if the undeferred ColorAnimation is then being immediately thrown away, rather than remaining undeferred... I'm not familiar with what VSM is doing under the covers so I don't know the answer off the top of my head.

  8. roxk commented on Jul 3, 2021

    @roxk

    Was about to report the same bug then found this issue. This issue is affecting VisualState.StateTrigger as well. In fact, I bet it's affecting anything that is bindable.

    A minimal repro for state trigger:

    <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="local:CustomControl">
                        <Border
                            x:Name="border"
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup>
                                    <VisualState x:Name="Normal"/>
                                    <VisualState x:Name="PointerOver">
                                        <VisualState.Setters>
                                            <Setter Target="border.Background" Value="Red"/>
                                        </VisualState.Setters>
                                        <VisualState.StateTriggers>
                                            <StateTrigger IsActive="{x:Bind IsShown, Mode=OneWay}"/> // Crashes with null pointer deference when binding this state trigger
                                        </VisualState.StateTriggers>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <TextBlock Text="Hello World"/>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
    

    Did the same debugging sequence and could confirm the reference for the state trigger is never set in Connect prior to updating its value.

  9. added
    bug
    product-winui3
    on Jun 15, 2023
  10. removed this from the WinUI 3.0 milestone on Feb 29, 2024
  11. sylveon commented on Jun 16, 2024

    @sylveon
    ContributorAuthor

    This 4 years old bug is, hilariously, still an issue in WinUI 3

  12. sylveon commented on Jun 16, 2024

    @sylveon
    ContributorAuthor

    However, the tags are incorrect. The bug was originally encountered in system XAML, with no WinUI at all.

  13. added
    team-Core
    on Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Bindingarea-Parserarea-VSMbugproduct-winui3team-Coreteam-Markup

    Type

    No type

    Projects

    • Status
      Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions