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 bundle may be built with non-utf8 but always execute with utf8. #118098
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.
@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):
@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.
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.
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?
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.
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?
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.
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?
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.
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?
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.
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.
Activity
dotnet-policy-service commentedon Jul 27, 2025
Tagging subscribers to this area: @agocke, @vitek-karas, @VSadov
See info in area-owners.md if you want to be subscribed.
elinor-fung commentedon Jul 28, 2025
@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):
CreateAndInject commentedon Jul 28, 2025
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).
agocke commentedon Jul 29, 2025
@jtschuster could you take a look?
jtschuster commentedon Jul 29, 2025
@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.
CreateAndInject commentedon Jul 30, 2025
In Visual Studio
What do you mean? The target framework in my uploaded project is .NET 5. My PC install all .NET 5 - .NET 10 SDK
jtschuster commentedon Aug 1, 2025
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 publishfrom the command line. Preview 7 should fix the issue within Visual Studio as well once it's released.CreateAndInject commentedon Aug 1, 2025
@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?
jtschuster commentedon Aug 1, 2025
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-sdksfrom 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.
CreateAndInject commentedon Aug 1, 2025
@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?
jtschuster commentedon Aug 1, 2025
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.
CreateAndInject commentedon Aug 1, 2025
Thanks
CreateAndInject commentedon Aug 1, 2025
@jtschuster Encoding.Default is always utf8 in .NET Core, so how this bug happen?
jtschuster commentedon Aug 1, 2025
Visual Studio runs the msbuild tasks on the desktop .NET Framework, where Encoding.Default will use the active code page. Using
dotnet publishwill 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.CreateAndInject commentedon Aug 1, 2025
@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?jtschuster commentedon Aug 1, 2025
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.
CreateAndInject commentedon Aug 1, 2025
OK, thanks