microsoft / microsoft/microsoft-ui-xaml

Inconsistent Windows.UI.Xaml.Interop.TypeName behavior

Open
#11,021 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

area-XamlCompiler bug team-Core
Dominant language
C++
Stars
8.4k
Forks
942
Avg merge
2d 7h
Merged PRs (30d)
105

Description

Describe the bug

I came across this as a sudden whim. I discovered that you can actually construct (or better say implicitly convert) a Windows.UI.Xaml.Interop from a string. If you have a viewmodel like this

    runtimeclass ViewModel
    {
        ViewModel();
        Windows.UI.Xaml.Interop.TypeName MyType;
    }

You can actually assign MyType in xaml using a string, something like

        <Button>
            <Button.DataContext>
                <local:ViewModel MyType="local:MainWindow" />
            </Button.DataContext>
        </Button>

If you put a breakpoint in the setter function, you can actually see the TypeName fields are correctly set.

Image

However, if you tried to explicitly construct it, it causes a runtime crash (curiously it compiles):

xmlns:interop="using:Windows.UI.Xaml.Interop" ...
        <Button>
            <Button.DataContext>
                <local:ViewModel>
                    <local:ViewModel.MyType>
                        <interop:TypeName>local:MainWindow</interop:TypeName>
                    </local:ViewModel.MyType>
                </local:ViewModel>
            </Button.DataContext>
        </Button>
Image

Which is the "inconsistent" I am talking about, because something that is implicitly constructed from a string, should also be able to explicitly constructed from a string

Why is this important?

The behavior should be consistent.

Steps to reproduce the bug

As OP.

Actual behavior

No response

Expected behavior

No response

Screenshots

No response

NuGet package version

WinUI 3 - Windows App SDK 1.8.5: 1.8.260209005

Windows version

Windows 10 (1809): Build 17763

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no source files, tests, or entry points. Start by reproducing the implicit string assignment and explicit Windows.UI.Xaml.Interop.TypeName construction from the two XAML snippets on Windows App SDK 1.8.5; done means the explicit form no longer crashes and behaves consistently with the implicit form.

Written by the indexing model from the issue text.

Assessment

Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.