Skip to content

String [Arguments] for IParsable types fail under Native AOT #7760

Closed

Description

@thomhurst

Summary

Under Native AOT, a string [Arguments] value for an IParsable<T> parameter type other than DateTime fails at run time with InvalidCastException. The same tests pass in source-gen (JIT) and reflection modes. The analyzer accepts these arguments, so they compile without any warning.

Reproduction

On main (340d34b), from tests/TUnit.TestProject:

dotnet publish -c Release -f net10.0 -p:Aot=true --use-current-runtime -o out
./out/TUnit.TestProject --treenode-filter "/*/*/StringToParsableArgumentsTests/*"

Expected and actual

Expected: all 12 tests in StringToParsableArgumentsTests pass.

Actual: 7 fail (Guid, Guid?, TimeSpan, TimeSpan?, DateTimeOffset, DateOnly, TimeOnly):

InvalidCastException: Cannot convert from 'System.String' to 'System.Guid' in Native AOT mode. No AOT converter was found in the AotConverterRegistry.

DateTime passes because it goes through IConvertible.

The string is passed through unchanged and converted at binding time by CastHelper.TryParseFromString (src/TUnit.Core/Helpers/CastHelper.cs:282), which finds Parse by reflection. Under AOT that reflection path doesn't find a usable Parse method. The T.Parse(...) emission in TypedConstantFormatter only covers attributes read from metadata, not the normal syntax path. A fix could follow #7759: have AotConverterGenerator register a string -> T converter that calls T.Parse(value, CultureInfo.InvariantCulture) directly.

Environment

  • TUnit main at 340d34b
  • .NET 10, osx-arm64, Native AOT publish

Activity

  1. added
    P2Medium: edge case, mode divergence, flaky test, or workaround exists
    on Nov 14, 2026
  2. added a commit that references this issue on Nov 14, 2026
    61aa866
  3. added a commit that references this issue on Nov 16, 2026
    399f07c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium: edge case, mode divergence, flaky test, or workaround existsbugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions