You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
.net 5 trimming causes crash on copying text #3903
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.
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.
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.
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"
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.
Activity
daisyTian0517 commentedon Dec 15, 2020
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.CarbonNeuron commentedon Dec 15, 2020
But there is already publish trimmed in the publish profile.
Could you please fork my repo and show the changes you made?
daisyTian0517 commentedon Dec 15, 2020
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>Add publish trimmed as mentioned in dotnet/wpf#3903
CarbonNeuron commentedon Dec 15, 2020
I have updated my repo to show the code you have shown. After publishing and running the file it has the same issue.
CarbonNeuron commentedon Dec 15, 2020
TestWPF.zip
This is the assembly that is built when trimming. Please upload your assembly if it works.
daisyTian0517 commentedon Dec 15, 2020
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.
CarbonNeuron commentedon Dec 15, 2020
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.
daisyTian0517 commentedon Dec 15, 2020
I get the exe in the publish folder like below shown,please point out if I misunderstand.

CarbonNeuron commentedon Dec 15, 2020
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"
daisyTian0517 commentedon Dec 16, 2020
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.CarbonNeuron commentedon Dec 16, 2020
While true, should we not still report these bugs somewhere?
ryalanms commentedon Jan 4, 2021
@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.
ThomasGoulet73 commentedon Mar 30, 2021
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.