PublishTrimmed trims too much (Could not load type 'System.Text.Json.JsonSerializer')
See original GitHub issueSteps to reproduce
- checkout https://github.com/VncDotnet/VncMatrix/tree/66fa86b446d2302ac4ae48723f8730e00dc720bd
- run
dotnet publish -r win-x64 -c Debug /p:PublishSingleFile=true /p:PublishTrimmed=true --self-contained
- run the built binary:
C:\Users\Benni\repositories\VncMatrix\VncMatrix\bin\Debug\netcoreapp3.0\win-x64\publish>VncMatrix.exe
Expected behavior
The program starts successfully.
Actual behavior
Note that this window only appears if you run the binary from a console - if I doubleclick it in an explorer window, the process exits without displaying that error window. Is that intended or a seperate bug? Shouldn’t it be the other way round?
Environment data
dotnet --info
output:
PS C:\Users\Benni\repositories\VncMatrix\VncMatrix> dotnet --info .NET Core SDK (gemäß "global.json"): Version: 3.0.100
Commit: 04339c3a26
Laufzeitumgebung:
OS Name: Windows
OS Version: 10.0.18362
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.0.100\
Host (useful for support):
Version: 3.0.0
Commit: 7d57652f33
.NET Core SDKs installed:
2.1.505 [C:\Program Files\dotnet\sdk]
2.1.801 [C:\Program Files\dotnet\sdk]
2.2.105 [C:\Program Files\dotnet\sdk]
3.0.100-preview9-014004 [C:\Program Files\dotnet\sdk]
3.0.100-rc1-014190 [C:\Program Files\dotnet\sdk]
3.0.100 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0-preview9.19424.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0-rc1.19457.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0-preview9-19423-09 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0-rc1-19456-20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.0.0-preview9-19423-09 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.0.0-rc1-19456-20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:6 (3 by maintainers)
Top Results From Across the Web
PublishTrimmed error with System.Text.Json
I am trying to publish my c# code with the argument -p:PublishTrimmed=true . It uses System.Text.Json, and gives me a warning.
Read more >Could not load type 'System.Text.Json.Serialization. ...
Create Blazor Web Application from Template. ASP NET 3.0 and run it - ALWAYS Json.Serialization error … Error Could not load type 'System....
Read more >Migrate from Newtonsoft.Json to System.Text.Json - .NET
Json features, migration will not be possible without significant changes. Allow or write numbers in quotes. Newtonsoft.Json can serialize or ...
Read more >Try the new System.Text.Json source generator - .NET Blog
This allows the ILLinker to trim out JSON converter types which will not be needed in the application at runtime. Similarly, inspecting input...
Read more >Feedback - Please add System.Text.Json support
Json support would be greatly appreciated. The Unity serialization system (even the new one) lacks features. Newtonsoft.Json is too random and ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m having basically the same problem, but with the issue that I have no idea how to find what roots I need to include, since the failure is deep inside private WPF code.
The top of a ~90 line stack trace is:
This is also an open issue in the Mono tracker (https://github.com/mono/linker/issues/712), which directed me at adding:
However that has no effect. The untrimmed version of the
PresentationFramework-SystemXmlLinq.dll
file is 18 KB, while the trimmed version (with or without the above directive) is 6 KB. Using dnSpy to look at the class constructor only sees GetType() reflection as anything likely to cause this problem, but making sureSystem.dll
was included didn’t help.Everything works fine with
PublishTrimmed
set to false.Overall, between this and other bugs I’ve encountered, PublishTrimmed has been quite a headache.
I’m running into a similar issue with a .NET Core 3.1 single file .exe that is using the PublishTrimmed option. When running it on a Windows 2008 R2 server (6.1.7601) I get the following error:
The type initializer for 'MS.Internal.SystemXmlLinqExtension' threw an exception.
The error does not occur when running the .exe locally on Windows 10 (Version 1909, OS build 18363.900)