You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
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.
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).
Activity
M0n7y5 commentedon Mar 8, 2024
Same for:
Android 10 API 29
Android 9 API 28
MichalPetryka commentedon Mar 8, 2024
runtime/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs
Lines 2197 to 2199 in 40ac297
Mono seems to return an empty GUID for types without
GuidAttributeinstead of generating a random one at runtime.Perksey commentedon Mar 8, 2024
Is the behaviour of this actually defined anywhere where the attribute is not present?
EDIT: helps if I read the full issue
M0n7y5 commentedon Mar 11, 2024
Would be nice to mention this behavior in docs tho. Anyways thx for clarification @MichalPetryka .
jkotas commentedon Mar 11, 2024
Do you just expect non-empty GUID values? Or do you expect the GUIDs to be exactly the same between Windows and non-Windows?
This behavior is more like a bug. We typically do not document bugs.
M0n7y5 commentedon Mar 12, 2024
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.
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)
am11 commentedon Mar 12, 2024
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)
jkotas commentedon Mar 13, 2024
Type.GUIDhas 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".
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.
jkotas commentedon Mar 13, 2024
PR with doc update: dotnet/dotnet-api-docs#9715
MichalPetryka commentedon Mar 13, 2024
Personally I think Mono should follow this behaviour here, if the type has no
GuidAttributethen it should get a generated GUID that's constant at least for as long the app is running (and unique among generated GUIDs).M0n7y5 commentedon Mar 14, 2024
Yeah it would be nice to have consistent behavior across platforms.
Skip tests that fail on Mono due to pre-existing runtime gaps