When using .NET 9 SDK or earlier, the string function returns the enum case name for FSharp.Core versions < 10. When upgrading to FSharp.Core 10.0.100, the string function returns the enum's integer value as a string.
Repro steps
- New .NET 9 F# console app with the following lines:
let enumValue = System.ConsoleColor.DarkBlue
printfn $"string: '{string enumValue}'"
printfn $"ToString(): '{enumValue.ToString()}'"
- Pin FSharp.Core version to 9.0.303.
- Add
global.json with SDK version set to 9.0.308.
dotnet run produces:
string: 'DarkBlue'
ToString(): 'DarkBlue'
- Update FSharp.Core version to 10.0.100.
dotnet run produces:
string: '1'
ToString(): 'DarkBlue'
Project used to reproduce behaviour above: FSharp.String.TestApp.zip
Expected behavior
string function returns the enum case name, i.e. the equivalent of calling the ToString() method.
Actual behavior
string function returns the enum case's integer value as a string.
Known workarounds
One of the following:
- Use the
ToString()method directly
- Use an earlier version of FSharp.Core
- Use the .NET 10 SDK.
When using .NET 9 SDK or earlier, the
stringfunction returns the enum case name for FSharp.Core versions < 10. When upgrading to FSharp.Core 10.0.100, thestringfunction returns the enum's integer value as a string.Repro steps
global.jsonwith SDK version set to 9.0.308.dotnet runproduces:dotnet runproduces:Project used to reproduce behaviour above: FSharp.String.TestApp.zip
Expected behavior
stringfunction returns the enum case name, i.e. the equivalent of calling theToString()method.Actual behavior
stringfunction returns the enum case's integer value as a string.Known workarounds
One of the following:
ToString()method directly