Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different behavior of DataTemplateSelector with enabled and disabled trim function #10302

Open
M-Muluc opened this issue Jan 15, 2025 · 3 comments
Labels
bug Something isn't working needs-triage Issue needs to be triaged by the area owners

Comments

@M-Muluc
Copy link

M-Muluc commented Jan 15, 2025

Describe the bug

trim removes the code section used in WinUI to modify DataTemplate

protected override DataTemplate? SelectTemplateCore(object item, DependencyObject container)
{
    // some code
}

Steps to reproduce the bug

  1. Enable trim and build project (in the attached repository trim is already enabled in the release and disabled in debug)

code

Expected behavior

Trim function does not delete used code sections.

Screenshots

Debug build:

2025-01-15.180449.mp4

Release build:

2025-01-15.180208.mp4

NuGet package version

None

Windows version

Windows 11 (24H2): Build 26100

Additional context

No response

@M-Muluc M-Muluc added the bug Something isn't working label Jan 15, 2025
@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Jan 15, 2025
@marcelwgn
Copy link
Collaborator

When trying to run your repro app in release, I get the following error:

1>C:\Program Files\dotnet\sdk\9.0.102\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(208,5): warning NETSDK1198: A publish profile with the name 'win-x64.pubxml' was not found in the project. Set the PublishProfile property to a valid file name.
1>C:\Users\User\.nuget\packages\microsoft.net.illink.tasks\8.0.12\build\Microsoft.NET.ILLink.targets(197,5): error NETSDK1102: Optimizing assemblies for size is not supported for the selected publish configuration. Please ensure that you are publishing a self-contained app.

Are there any steps I'm missing to run it in release?

@marcelwgn marcelwgn added needs-author-feedback Asked author to supply more information. and removed needs-triage Issue needs to be triaged by the area owners labels Jan 16, 2025
@ghost1372
Copy link
Contributor

ghost1372 commented Jan 16, 2025

@M-Muluc Disable Trim for Release Mode: (i tested on Release Mode and it is working fine @marcelwgn also Optimizing assemblie error will be fixed by disabling Trim)

<PublishTrimmed Condition="'$(Configuration)' != 'Debug'">False</PublishTrimmed>

or if you dont want to disable trim, you can add a publish profile.
add win-x64.pubxml under Properties\PublishProfile folder:

<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
  <PropertyGroup>
    <Configuration>Release</Configuration>
    <Platform>x64</Platform>
    <PublishDir>bin\x64\Release\net8.0-windows10.0.19041.0\publish\</PublishDir>
    <PublishProtocol>FileSystem</PublishProtocol>
    <_TargetId>Folder</_TargetId>
    <TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    <SelfContained>false</SelfContained>
    <PublishSingleFile>false</PublishSingleFile>
    <PublishReadyToRun>false</PublishReadyToRun>
  </PropertyGroup>
</Project>

@M-Muluc
Copy link
Author

M-Muluc commented Jan 16, 2025

@marcelwgn Sorry, gitignore deleted the files in question. I didn't modify them. I added them to the repository just in case.

Thanks @ghost1372 for the suggested solutions to the problem, it worked.

I'll leave the Issue open for now, as I believe trim should not remove these sections of code since they are used inside the WinUI. If I am wrong, you can close the Issue.

protected override DataTemplate? SelectTemplateCore(object item, DependencyObject container)
{
    return (item as ContentViewModel) switch
    {
        GreenContentViewModel => GreenTemplate,
        RedContentViewModel => RedTemplate,
        _ => new DataTemplate()
    };
}

@microsoft-github-policy-service microsoft-github-policy-service bot added needs-triage Issue needs to be triaged by the area owners and removed needs-author-feedback Asked author to supply more information. labels Jan 16, 2025
@M-Muluc M-Muluc changed the title Different behavior of DataTemplateSelector in release and debug builds Different behavior of DataTemplateSelector with enabled and disabled trim function Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-triage Issue needs to be triaged by the area owners
Projects
None yet
Development

No branches or pull requests

3 participants