Skip to content

Conversation

@AlekseyTs
Copy link
Contributor

Fixes #81381

@AlekseyTs AlekseyTs requested review from agocke and jaredpar November 20, 2025 22:07
@AlekseyTs AlekseyTs requested a review from a team as a code owner November 20, 2025 22:07
@AlekseyTs
Copy link
Contributor Author

@dotnet/roslyn-compiler Please review

@AlekseyTs
Copy link
Contributor Author

@jaredpar, @agocke Do you have any comments?

internal readonly bool IsScriptCommandLineParser;
private static readonly char[] s_searchPatternTrimChars = new char[] { '\t', '\n', '\v', '\f', '\r', ' ', '\x0085', '\x00a0' };
internal const string ErrorLogOptionFormat = "<file>[,version={1|1.0|2|2.1}]";
private static bool s_registeredEncodingProvider = CodePagesEncodingProvider.Instance == null;
Copy link
Member

@jjonescz jjonescz Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can CodePagesEncodingProvider.Instance be null here? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not control behavior of the API. In theory result of the property could be null. We have similar check in other places in our codebase. If it cannot be null, there is no harm in checking it anyway.

Assert.Equal("Unicode (UTF-8)", parsedArgs.Encoding.EncodingName);

parsedArgs = DefaultParse(new[] { "/CodePage:1252", "a.cs" }, WorkingDirectory);
parsedArgs.Errors.Verify();
Copy link
Member

@jjonescz jjonescz Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this fail without the fix? #Resolved

Copy link
Contributor Author

@AlekseyTs AlekseyTs Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this fail without the fix?

Yes, when run on CoreCLR the test fails without the fix with the error from the issue.

@AlekseyTs AlekseyTs requested a review from jjonescz November 21, 2025 16:00
@AlekseyTs
Copy link
Contributor Author

@dotnet/roslyn-compiler For a second review

{
try
{
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
Copy link
Member

@agocke agocke Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not call RegisterProvider unconditionally before calling GetEncoding? The reason I ask is that my memory was that providing a specific encoding to the compiler was relatively rare. I think we usually don’t get a specific encoding and just assume utf8. And I think utf8 is both the most common encoding (inc ascii) and the recommended encoding.

So if we’re already in an edge case, could we assume that if someone needs a specific code page it might be a non-registered one? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From documentation of the APIs, it is my understanding that calling Encoding.RegisterProvider might overwrite previous setup. So, if the environment was properly setup to support certain encoding, this call might change that setup. I.e. the encoding will be supported but by a different provider. Therefore, I felt that it might make sense to not mess with providers, unless we run into a failure.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider capturing this in a comment, it probably won't be obvious to future readers.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Def agree. The logic/flow here is complex for me (nested try/catches with gotos). I think this def warrants some explanation on what's going on.

@AlekseyTs AlekseyTs requested a review from a team November 24, 2025 17:36
@AlekseyTs
Copy link
Contributor Author

@dotnet/roslyn-compiler For a second review

1 similar comment
@AlekseyTs
Copy link
Contributor Author

@dotnet/roslyn-compiler For a second review

Copy link
Member

@CyrusNajmabadi CyrusNajmabadi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. That helps a lot. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

After installing VS2026 all Builds fail with CSC : error CS2016: Code page '1252' is invalid or not installed

4 participants