Skip to content

System.Type.GUID is empty on Android #99459

Open

Description

@M0n7y5

Description

On Windows
F1k99tEpDe

On Android (Android 14 API 34)
image

I assume this is bug since i was not able to obtain any relevant information about this kind of behavior from the official docs:
https://learn.microsoft.com/en-us/dotnet/api/system.type.guid?view=net-8.0#system-type-guid

Reproduction Steps

Just do run this code on windows and android

var id = typeof(YourCustomType).GUID;

Expected behavior

I excpect non empty GUID values

Actual behavior

GUID values are empty on android, possibly on other platforms too

Regression?

no idea

Known Workarounds

nope

Configuration

.Net 8 MAUI Blazor Hybrid
Windows 11 22H2 22621.3155
x64

Other information

No response

Activity

  1. ghost added
    needs-area-label
    on Mar 8, 2024
  2. added
    untriaged
    on Mar 8, 2024
  3. M0n7y5 commented on Mar 8, 2024

    @M0n7y5
    Author

    Same for:
    Android 10 API 29
    Android 9 API 28

  4. MichalPetryka commented on Mar 8, 2024

    @MichalPetryka
    Contributor

    object[] att = GetCustomAttributes(typeof(System.Runtime.InteropServices.GuidAttribute), true);
    if (att.Length == 0)
    return Guid.Empty;

    Mono seems to return an empty GUID for types without GuidAttribute instead of generating a random one at runtime.

  5. added
    area-VM-reflection-mono
    and removed
    needs-area-label
    on Mar 8, 2024
  6. Perksey commented on Mar 8, 2024

    @Perksey
    Member

    Is the behaviour of this actually defined anywhere where the attribute is not present?

    EDIT: helps if I read the full issue

  7. M0n7y5 commented on Mar 11, 2024

    @M0n7y5
    Author

    Would be nice to mention this behavior in docs tho. Anyways thx for clarification @MichalPetryka .

  8. jkotas commented on Mar 11, 2024

    @jkotas
    Member

    I expect non empty GUID values

    Do you just expect non-empty GUID values? Or do you expect the GUIDs to be exactly the same between Windows and non-Windows?

    Would be nice to mention this behavior in docs tho.

    This behavior is more like a bug. We typically do not document bugs.

  9. M0n7y5 commented on Mar 12, 2024

    @M0n7y5
    Author

    Do you just expect non-empty GUID values? Or do you expect the GUIDs to be exactly the same between Windows and non-Windows?

    I expect exactly what i wrote ... I expect non empty GUID values. That means i'll be happy with any values ... Well unique value per type to be specific.

    This behavior is more like a bug. We typically do not document bugs.

    Is it a bug tho? It looks like a mono feature/behavior. Basically strips down guids of not marked types by the GuidAttribute in order to reduce size. (i assume)

  10. am11 commented on Mar 12, 2024

    @am11
    Member

    It looks like a mono feature/behavior

    Yes, this answer (from 2011) agrees with you https://stackoverflow.com/a/8666656.

    (If possible, would be good to make Type.GUID output consistent across runtimes rather than creating a third kind of output)

  11. jkotas commented on Mar 13, 2024

    @jkotas
    Member

    Type.GUID has been designed for built-in COM interop. Any use of this property outside built-in COM interop is questionable.

    It is not unusual to see people misusing Type.Guid as unique type identifier. (It is not actually unique type identifier. Nothing prevents two different .NET types to have the same COM GUID and there are valid scenarios where this can happen.)

    In Native AOT, Type.Guid generates a random guid for types without explicitly specified one to make this sort of misuse "work".

    If possible, would be good to make Type.GUID output consistent across runtimes rather than creating a third kind of output)

    It would require porting somewhat complicated algorithm used by built-in COM to generate the Guid. This algorithm creates the Guid by computing MD5 hash over the type name and all methods visible to built-in COM interop. This algorithm is not compatible with trimming, so it makes the consistency argument futile for runtime variants that are typically used with trimming.

  12. jkotas commented on Mar 13, 2024

    @jkotas
    Member

    PR with doc update: dotnet/dotnet-api-docs#9715

  13. MichalPetryka commented on Mar 13, 2024

    @MichalPetryka
    Contributor

    In Native AOT, Type.Guid generates a random guid for types without explicitly specified one to make this sort of misuse "work".

    Personally I think Mono should follow this behaviour here, if the type has no GuidAttribute then it should get a generated GUID that's constant at least for as long the app is running (and unique among generated GUIDs).

  14. M0n7y5 commented on Mar 14, 2024

    @M0n7y5
    Author

    Yeah it would be nice to have consistent behavior across platforms.

  15. removed
    untriaged
    on Jul 3, 2024
  16. added this to the Future milestone on Jul 3, 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-VM-reflection-mono

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions