Skip to content

.net 5 trimming causes crash on copying text #3903

Open

Description

@CarbonNeuron
  • .NET Core Version: 5.0.101
  • Windows version: 20H2
  • Does the bug reproduce also in WPF for .NET Framework 4.8?: No
  • Is this bug related specifically to tooling in Visual Studio (e.g. XAML Designer, Code editing, etc...)? No
  • Security issues and bugs should be reported privately, learn more via our responsible disclosure guidelines.

Problem description: I am building a self-contained trimmed publish release of a project using .net 5, and using trimming. If you try to copy from the Text boxes in the GUI it will crash. This only happens with trimming.

Actual behavior:
Faulting application name: TestWPF.exe, version: 1.0.0.0, time stamp: 0x5fbf1139 Faulting module name: ntdll.dll, version: 10.0.19041.662, time stamp: 0x5f641e44 Exception code: 0xc0000409 Fault offset: 0x00087160 Faulting process id: 0x342c Faulting application start time: 0x01d6cfff6daa978a Faulting application path: C:\Users\Carbon\source\repos\TestWPF\TestWPF\bin\Release\net5.0-windows\publish\TestWPF.exe Faulting module path: C:\Windows\SYSTEM32\ntdll.dll Report Id: e5c5c421-412f-4a5f-aa52-d412120410da Faulting package full name: Faulting package-relative application ID:

Expected behavior: it copies the text to clipboard.

Minimal repro: https://github.com/CarbonNeuron/WPFCopyCrash make sure to run the published file and not the debug one.

Activity

  1. daisyTian0517 commented on Dec 15, 2020

    @daisyTian0517

    I checked your .csproj file and add <PublishTrimmed>true</PublishTrimmed> to PropertyGroup, then published the app refer to the steps in Publish a single file app - Visual Studio. There is no problem for copies of the text to clipboard or copies of the text from clipboard with trimming.

  2. CarbonNeuron commented on Dec 15, 2020

    @CarbonNeuron
    Author

    But there is already publish trimmed in the publish profile.
    Could you please fork my repo and show the changes you made?

  3. daisyTian0517 commented on Dec 15, 2020

    @daisyTian0517

    I didn't see <PublishTrimmed>true</PublishTrimmed> in your csproj and update csproj as below:
    <Project Sdk="Microsoft.NET.Sdk.WindowsDesktop"> <PropertyGroup> <OutputType>WinExe</OutputType> <TargetFramework>net5.0-windows</TargetFramework> <UseWPF>true</UseWPF> <TrimMode>link</TrimMode> <PublishTrimmed>true</PublishTrimmed> <IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract> </PropertyGroup> <ItemGroup> <TrimmerRootAssembly Include="System.Runtime" /> <TrimmerRootAssembly Include="System.Runtime.Extensions" /> </ItemGroup> </Project>

  4. CarbonNeuron commented on Dec 15, 2020

    @CarbonNeuron
    Author

    I have updated my repo to show the code you have shown. After publishing and running the file it has the same issue.

  5. CarbonNeuron commented on Dec 15, 2020

    @CarbonNeuron
    Author

    TestWPF.zip
    This is the assembly that is built when trimming. Please upload your assembly if it works.

  6. daisyTian0517 commented on Dec 15, 2020

    @daisyTian0517

    Did you clean and rebuild your project after the update?Did you try to publish your project in other device?By the way, my visual studio version is 16.8.1.Here is my file.

  7. CarbonNeuron commented on Dec 15, 2020

    @CarbonNeuron
    Author

    Your file is 142MB, which is not trimmed. My file is 70MB. Make sure you are using the publish profile and not just building.

    But yes, if you don't trim, it will work fine. But this is not the issue.

  8. daisyTian0517 commented on Dec 15, 2020

    @daisyTian0517

    I get the exe in the publish folder like below shown,please point out if I misunderstand.
    Capture

  9. CarbonNeuron commented on Dec 15, 2020

    @CarbonNeuron
    Author

    The csproj does not matter. Make sure you are publishing it using the publish profile. You should get console output while building that says you are trimming. And it should take abnormally long to "build"

  10. daisyTian0517 commented on Dec 16, 2020

    @daisyTian0517

    The Member-Level Trimming part points out: Member-level trimming(<TrimMode>Link</TrimMode>) has more risk than assembly level trimming, and so is being released as an experimental feature, that is not yet ready for mainstream adoption.

  11. CarbonNeuron commented on Dec 16, 2020

    @CarbonNeuron
    Author

    While true, should we not still report these bugs somewhere?

  12. ryalanms commented on Jan 4, 2021

    @ryalanms
    Member

    @CarbonNeuron: Thank you for the report. WPF has not done any work to support trimming yet.

    Please continue reporting any issues. All of this feedback is taken in to account during planning for the next release.

  13. added this to the Future milestone on Jan 7, 2021
  14. added
    Bug
    on Jan 7, 2021
  15. ThomasGoulet73 commented on Mar 30, 2021

    @ThomasGoulet73
    Contributor

    I just reproduced this error in .Net 5.0.3. This only occurs with <TrimMode>Link</TrimMode>.

    I fixed it by including <TrimmerRootAssembly Include="System.Runtime.InteropServices" /> in my csproj.

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

    Bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions