Skip to content

.NET bundle may be built with non-utf8 but always execute with utf8. #118098

Closed

Description

@CreateAndInject

中文.7z

Create a project with Chinese chars, publish as a single bundle, the target is longer runnable.
The issue is: The bundle is built with non-utf8 encoding(Maybe default encoding of Windows on my PC), but when executing, system always parses it as utf8 encoding.

Image

Activity

  1. added
    untriaged
    on Jul 27, 2025
  2. added
    needs-area-label
    on Jul 27, 2025
  3. added and removed
    needs-area-label
    on Jul 27, 2025
  4. dotnet-policy-service commented on Jul 27, 2025

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @agocke, @vitek-karas, @VSadov
    See info in area-owners.md if you want to be subscribed.

  5. elinor-fung commented on Jul 28, 2025

    @elinor-fung
    Member

    @CreateAndInject what version of the .NET SDK are you using to publish? Would you be able to try the latest .NET 10 preview? @jtschuster has made a number of changes around bundling in the latest release.

    Would you also be able to share (ideally as just an attachment on github - the file hosting site in the description is blocked for me):

  6. CreateAndInject commented on Jul 28, 2025

    @CreateAndInject
    Author

    @CreateAndInject what version of the .NET SDK are you using to publish? Would you be able to try the latest .NET 10 preview?

    You can see from my uploaded project. I try .NET 5-10.

    I think you can reproduce it from the PC which default encoding is Chinese chars(eg. gbk).

  7. added this to the 10.0.0 milestone on Jul 29, 2025
  8. removed
    untriaged
    on Jul 29, 2025
  9. agocke commented on Jul 29, 2025

    @agocke
    Member

    @jtschuster could you take a look?

  10. jtschuster commented on Jul 29, 2025

    @jtschuster
    Member

    @CreateAndInject Was this published in Visual Studio, or on the command line? And which .NET 10 preview sdk are you using? The bundler at one point used Encoding.Default which would use the active code page in .NET Framework / when building in VS. With the latest changes in main (and in preview 6), no strings should be written in anything but UTF-8.

  11. CreateAndInject commented on Jul 30, 2025

    @CreateAndInject
    Author

    Was this published in Visual Studio, or on the command line?

    In Visual Studio

    And which .NET 10 preview sdk are you using?

    What do you mean? The target framework in my uploaded project is .NET 5. My PC install all .NET 5 - .NET 10 SDK

  12. jtschuster commented on Aug 1, 2025

    @jtschuster
    Member

    Ah, it looks like the fix for this didn't make it into .NET 10 preview 6. In the meantime, you should be able to work around the issue using dotnet publish from the command line. Preview 7 should fix the issue within Visual Studio as well once it's released.

  13. CreateAndInject commented on Aug 1, 2025

    @CreateAndInject
    Author

    Ah, it looks like the fix for this didn't make it into .NET 10 preview 6. In the meantime, you should be able to work around the issue using dotnet publish from the command line. Preview 7 should fix the issue within Visual Studio as well once it's released.

    @jtschuster How about the PC doesn't install .NET 10 preview? Is the next Visual Studio update will fix the bug even if only .NET 5 is installed?

  14. jtschuster commented on Aug 1, 2025

    @jtschuster
    Member

    I'm not sure I follow. .NET 5 is out of support and won't receive any new fixes. If you can publish for .NET 10, you are probably using a .NET 10 SDK. Do you have a global.json for your project that specifies the sdk version? If not, can you run dotnet --list-sdks from a Visual Studio Developer Command Prompt and paste the output?

    Also, if you're able to upload a binlog of the publish to Github, that would be very helpful. I'm unable to access your link above.

  15. CreateAndInject commented on Aug 1, 2025

    @CreateAndInject
    Author

    If you can publish for .NET 10, you are probably using a .NET 10 SDK.

    @jtschuster I don't talk about my PC only. I mean, if a PC install .NET 9 only(or any other version eg. 5/6/7/8 but not 10), is this bug will be fixed also when next Visual Studio update?

  16. jtschuster commented on Aug 1, 2025

    @jtschuster
    Member

    The issue shouldn't be present in the .NET 9 SDK (or any previous SDKs). The bug looks to have been introduced here by using Encoding.Default and fixed here, both released only in .NET 10 previews.

  17. CreateAndInject commented on Aug 1, 2025

    @CreateAndInject
    Author

    Thanks

  18. CreateAndInject commented on Aug 1, 2025

    @CreateAndInject
    Author

    In .NET Core, the Default property always returns the UTF8Encoding. UTF-8 is supported on all the operating systems (Windows, Linux, and macOS) on which .NET Core applications run.

    @jtschuster Encoding.Default is always utf8 in .NET Core, so how this bug happen?

  19. jtschuster commented on Aug 1, 2025

    @jtschuster
    Member

    Visual Studio runs the msbuild tasks on the desktop .NET Framework, where Encoding.Default will use the active code page. Using dotnet publish will run the build on modern .NET / .NET Core, which would use UTF-8, and should enable you to build the project without waiting for the next VS update.

  20. CreateAndInject commented on Aug 1, 2025

    @CreateAndInject
    Author

    Visual Studio runs the msbuild tasks on the desktop .NET Framework, where Encoding.Default will use the active code page. Using dotnet publish will run the build on modern .NET / .NET Core, which would use UTF-8, and should enable you to build the project without waiting for the next VS update.

    @jtschuster But I see the latest Bundler.cs uses ReadOnlySpan<byte> which doesn't exist on .NET Framework, so how can Visual Studio runs the msbuild tasks on the desktop .NET Framework?

  21. jtschuster commented on Aug 1, 2025

    @jtschuster
    Member

    The project uses the System.Memory nuget package which provides a System.Span type built on top of .NET Framework. We use packages like this to allow us to utilize the latest .NET niceties in projects that have to support both .NET and .NET Framework.

  22. CreateAndInject commented on Aug 1, 2025

    @CreateAndInject
    Author

    The project uses the System.Memory nuget package which provides a System.Span type built on top of .NET Framework. We use packages like this to allow us to utilize the latest .NET niceties in projects that have to support both .NET and .NET Framework.

    OK, thanks

  23. locked and limited conversation to collaborators on Sep 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

  • Status
    No status

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions