Skip to content

UnsafeAccessor throws MissingFieldException on generic field (T) #92633

Closed as not planned

Description

@AoshiW

Description

UnsafeAccessor throws MissingFieldException on generic field (T) in generic type, where genetic T is:

  • class (e.g. string)
  • struct that has class as a generic parameter (e.g. ArraySegment<string>)

Reproduction Steps

[UnsafeAccessor(UnsafeAccessorKind.Field, Name = "_items")]
static extern ref string[] GetItems(List<string> list);

GetItems(new());

Expected behavior

getting field

Actual behavior

throws exception

System.MissingFieldException: Field not found: 'System.Collections.Generic.List`1._items'.

Regression?

No response

Known Workarounds

No response

Configuration

.NET SDK: 8.0.100-rc.1.23455.8

Other information

No response

Activity

  1. ghost added
    needs-area-label
    on Sep 26, 2023
  2. ghost added
    untriaged
    on Sep 26, 2023
  3. changed the title [-]`UnsafeAccessor` throws `MissingFieldException` on generic array field (`T[]`)[/-] [+]`UnsafeAccessor` throws `MissingFieldException` on generic field (`T`)[/+] on Sep 26, 2023
  4. added and removed
    needs-area-label
    on Sep 26, 2023
  5. jkotas commented on Sep 26, 2023

    @jkotas
    Member
  6. AaronRobinsonMSFT commented on Sep 26, 2023

    @AaronRobinsonMSFT
    Member

    Boo. For my original implementation of the signature match this worked. When I switched to the more robust, but stricter, built-in element compare this support was lost. Le sigh. There is little chance this sort of fix meets the servicing bar. I will take a little bit to try and make it work, but this is likely a .NET 9 fix.

  7. AaronRobinsonMSFT commented on Sep 26, 2023

    @AaronRobinsonMSFT
    Member

    Yep, this is a future fix. If the T is anywhere in the field or method signature this is going to fail.

    Let me add some tests for this.

  8. removed
    untriaged
    on Sep 26, 2023
  9. added this to the 9.0.0 milestone on Sep 26, 2023
  10. AaronRobinsonMSFT commented on Sep 26, 2023

    @AaronRobinsonMSFT
    Member

    With how this is currently implemented there is some overlap with #89439. The core issue being how we parse and compare signatures.

  11. added
    disabled-test
    on Sep 26, 2023
  12. AaronRobinsonMSFT commented on Sep 26, 2023

    @AaronRobinsonMSFT
    Member

    I've added disabled tests in #92657 and fixed some issues with NAOT.

  13. AaronRobinsonMSFT commented on Feb 17, 2024

    @AaronRobinsonMSFT
    Member

    I'm going to close this as duplicate since this work will be included in #89439. I've already got the static/instance fields working and have re-enabled the failing tests in my working branch.

  14. locked and limited conversation to collaborators on Mar 18, 2024
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

    area-System.Runtime.CompilerServicesdisabled-test

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions