Skip to content

Question about changed behavior of string interpolations in NativeAOT in the .NET 11 rc1 SDK #20757

Open

Description

@Numpsy

Hi,

Not sure if this is a bug, or an expected change after #19971, but as it came across as a breaking change to me I'll ask in case.

When doing testing with fable-hub/Scriptorium#21 I noticed that if I have the code

let now = System.DateTime.UtcNow

let startAt =
    $"%02d{now.Hour}:%02d{now.Minute}:%02d{now.Second}"

and compile that with NativeAOT using the .NET 10 SDK then the resulting executable works correctly, but compiling the same code with the .NET11-RC1 SDK then it crashes at runtime with an exception similar to the one in fable-hub/Scriptorium#21.

This doesn't seem ideal, even given the known issues with F# style format specifiers, if it worked before and doesn't now?

fwiw, looking at the binary with ILSpy, the .NET 10 build that works decompiles as

string startAt2 = (startAt2@10 = ExtraTopLevelOperators.PrintFormatToString(new PrintfFormat<string, Unit, string, string, Tuple<int, int, int>>("%02d%P():%02d%P():%02d%P()", new object[3]
{
    Program.now.Hour,
    Program.now.Minute,
    Program.now.Second
}, null)));

and the .NET 11 build that doesn't shows as

string startAt2 = (startAt2@9 = ExtraTopLevelOperators.PrintFormatToString(new PrintfFormat<FSharpFunc<int, string>, Unit, string, string, int>("%02d")).Invoke(Program.now.Hour) + ":" + ExtraTopLevelOperators.PrintFormatToString(new PrintfFormat<FSharpFunc<int, string>, Unit, string, string, int>("%02d")).Invoke(Program.now.Minute) + ":" + ExtraTopLevelOperators.PrintFormatToString(new PrintfFormat<FSharpFunc<int, string>, Unit, string, string, int>("%02d")).Invoke(Program.now.Second));

Known workarounds

Doing $"{now.Hour:D2}:{now.Minute:D2}:{now.Second:D2}" works in the RC1 SDK, so it can at least be made to work that way.

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions