WindowsAppSDK icon indicating copy to clipboard operation
WindowsAppSDK copied to clipboard

Publishing a C# unpackaged app trimmed causes TextBlock.Inlines collection items to loose type information

Open DHancock opened this issue 1 year ago • 1 comments

Describe the bug

I'm parsing a TextBlock.Inlines collection to see if it contains a Hyperlink. The code works for normal Debug and Release builds, but fails when published trimmed. It seems that the contents of the Inlines collection have lost some type information, now only ever containing items of type Microsoft.UI.Xaml.Documents.Inline

Steps to reproduce the bug

For example, with the following xaml:

<TextBlock>
  <Hyperlink NavigateUri="https://www.google.com">
    <Run Text="GoTo Google"/>
  </Hyperlink>      
</TextBlock>

When parsing the visual tree with:

switch (uielement)
{
  case TextBlock tb when tb.Inlines.Any(x => x is Hyperlink):
  {
    // code to add the Hyperlink area to the passthrough rectangles
    break;
  }
}

The code fails to find a Hyperlink inline when published trimmed using a publishing profile containing:

<PublishTrimmed>true</PublishTrimmed>

Expected behavior

Type information is preserved

Screenshots

No response

NuGet package version

Windows App SDK 1.6.0: 1.6.240829007

Packaging type

Unpackaged

Windows version

Windows 11 version 22H2 (22621, 2022 Update)

IDE

Visual Studio 2022

Additional context

the project references

<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.1.3" />

DHancock avatar Sep 16 '24 19:09 DHancock

~~Fixed in CsWinRT version 2.1.5~~

Edit: No it isn't. I was just too hung over to test it properly...

DHancock avatar Oct 12 '24 09:10 DHancock