Skip to content

NativeAOT readiness #1469

Closed

Description

We should vet this library for NativeAOT readiness.

See https://github.com/dotnet/Nerdbank.Streams/pull/783/files for an example of how this can be done.

Activity

  1. eerhardt commented on Jun 19, 2025

    @eerhardt
    Member

    One place that will need to be addressed is:

    /// <summary>
    /// A helper method to get field's value given the object and the field name.
    /// </summary>
    private static object? GetFieldValue(object obj, string fieldName)
    {
    Requires.NotNull(obj, nameof(obj));
    Requires.NotNullOrEmpty(fieldName, nameof(fieldName));
    FieldInfo? field = obj.GetType().GetTypeInfo().GetDeclaredField(fieldName);
    if (field is object)
    {
    return field.GetValue(obj);
    }
    return null;
    }
    /// <summary>
    /// The field names of "async state machine" are not fixed; the workaround is to find the field based on the suffix.
    /// </summary>
    private static object? GetStateMachineFieldValueOnSuffix(IAsyncStateMachine stateMachine, string suffix)
    {
    Requires.NotNull(stateMachine, nameof(stateMachine));
    Requires.NotNullOrEmpty(suffix, nameof(suffix));
    IEnumerable<FieldInfo>? fields = stateMachine.GetType().GetTypeInfo().DeclaredFields;
    FieldInfo? field = fields.FirstOrDefault((f) => f.Name.EndsWith(suffix, StringComparison.Ordinal));
    if (field is object)
    {
    return field.GetValue(stateMachine);
    }
    return null;
    }

    This is using reflection to inspect a bunch of async state machine fields. If this code is only used for diagnostics, maybe the warnings can be suppressed? Or hidden behind a feature switch.

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

Metadata

Metadata

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions