Description
Description
I'm not sure if this was intentional, and I'm fine if it is and I can adjust accordingly, but I wanted to report this in case it was unintentional.
If the .runtimeconfig.json
or .deps.json
has a UTF-8 BOM then it will prevent the app from launching. It used to work fine in .NET 9 and before.
I'm running into this because I build my app (Paint.NET) in Visual Studio as a framework-dependent app (so as to launch from VS). Then during my custom packaging process written in C#, I transform these .json
files so they are appropriate for self-contained deployment. I write out the new file this using Encoding.UTF8
, as that's the standard way of doing things nowadays as I understand it.
But now, with .NET 10 Preview, my app works fine from VS but the packaged version does not launch at all and gives the error listed below. I was able to figure out that it was the presence of the UTF-8 BOM at the start of the file that causes this.
Reproduction Steps
- Build any app of your choice. Console, desktop, whatever.
- Open up its
.runtimeconfig.json
file with Notepad - Click on File -> Save As
- In the Save dialog, click the dropdown for "Encoding:" (to the left of the Save button) and choose "UTF-8 with BOM".
- Click the Save button and confirm that you want to overwrite the existing file
- Now try to run your app
Expected behavior
The app should work just fine.
Actual behavior
The app will not launch. If it's a console app then you'll see something like this printed to the console:
A JSON parsing exception occurred in [D:\src\github\rickbrew\IlLinkNotImplException113031\bin\Release\net10.0\IlLinkNotImplException113031.runtimeconfig.json], offset 0 (line 1, column 1): Invalid value.
Invalid runtimeconfig.json [D:\src\github\rickbrew\IlLinkNotImplException113031\bin\Release\net10.0\IlLinkNotImplException113031.runtimeconfig.json] [D:\src\github\rickbrew\IlLinkNotImplException113031\bin\Release\net10.0\IlLinkNotImplException113031.runtimeconfig.dev.json]
If you use a hex edit to peek at the file, you'll see it starts with a UTF-8 BOM (byte order marker):
Regression?
Yes, this worked in .NET 9 and earlier. The .runtimeconfig.json
and .deps.json
for my app have a UTF-8 BOM at the start of the file and have no problems.
Known Workarounds
Don't include a BOM when editing/transforming/modifying these .json
files. Use Encoding.ASCII
instead of Encoding.UTF8
.
Configuration
.NET 10 Preview 4 x64
Windows 11 Pro build 26100.4188
Ryzen 9 9950X
96GB RAM
Other information
No response
Metadata
Metadata
Assignees
Type
Projects
Status