Skip to content

UTF-8 BOM causes .deps.json and .runtimeconfig.json to break and prevent app from launching #115915

Closed
@rickbrew

Description

@rickbrew

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

  1. Build any app of your choice. Console, desktop, whatever.
  2. Open up its .runtimeconfig.json file with Notepad
  3. Click on File -> Save As
  4. In the Save dialog, click the dropdown for "Encoding:" (to the left of the Save button) and choose "UTF-8 with BOM".
  5. Click the Save button and confirm that you want to overwrite the existing file
  6. 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):

Image

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

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions