OverflowException in LoggerMessageGenerator.GetNonRandomizedHashCode #110698
Labels
area-Extensions-Logging
in-pr
There is an active PR which will close this issue when it is merged
source-generator
Indicates an issue with a source generator feature
Milestone
Description
The source generator in Microsoft.Extensions.Logging.Abstractions throws OverflowException when it attempts to generate an EventId for some logger method names. Pronounceable names that trigger this error include
Dzoggee
,Juzzwenn
,Bzuengdom
,Covieeszu
,Ennudkilw
,Fawiinska
,Haikshyke
,Hyklyytja
,Kirraphas
,Nuthvausu
,Orluavjee
,Piaanwatz
,Ponkpauij
,Ruakszyrn
, andSazkwinuo
.Reproduction Steps
EventIdHashOverflow.csproj:
LoggerExtensions.cs:
Attempt to build this project.
Expected behavior
The build should succeed.
Actual behavior
CSC : warning CS8785: Generator 'LoggerMessageGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'OverflowException' with message 'Negating the minimum value of a twos complement number is invalid.'.
LoggerExtensions.cs(8,36,8,43): error CS8795: Partial method 'LoggerExtensions.Dzoggee(ILogger)' must have an implementation part because it has accessibility modifiers.
Regression?
No response
Known Workarounds
Specify LoggerMessageAttribute.EventId instead of letting it be generated automatically.
Configuration
.NET SDK 9.0.101
Other information
OverflowException is thrown by the Math.Abs(Int32.MinValue) call here:
runtime/src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/LoggerMessageGenerator.Parser.cs
Lines 850 to 862 in 9cb3b72
There is similar code in other source generators too:
runtime/src/libraries/Microsoft.Extensions.Options/gen/OptionsSourceGenContext.cs
Lines 68 to 81 in 5a9362f
Making GetNonRandomizedHashCode return 0 in this case would make every nonnegative
int
return value correspond to two values ofuint result
.The text was updated successfully, but these errors were encountered: