dotnet / dotnet/dotnet-api-docs
CLR and compilers require specific GUID format
- Dominant language
- C#
- Stars
- 949
- Forks
- 1.7k
- Avg merge
- 3d 27m
- Merged PRs (30d)
- 49
Description
The GuidAttribute topic says: "The string passed to the attribute must be in a format that is an acceptable constructor argument for the type Guid." However, the C# compiler of Visual Studio 2017 version 15.9.5 reports error CS0591 if given `[Guid("{9ED54F84-A89D-4fcd-A854-44251E925F09}")]`, even though `new Guid("{9ED54F84-A89D-4fcd-A854-44251E925F09}")` works fine. Please document that only the `"9ED54F84-A89D-4fcd-A854-44251E925F09"` format is allowed.
The `GuidAttribute(string)` constructor actually does not parse the string at all. The validation is done by the C# and Visual Basic compilers ([CSharpAttributeData.DecodeGuidAttribute](https://github.com/dotnet/roslyn/blob/Visual-Studio-2017-Version-15.9/src/Compilers/CSharp/Portable/Symbols/Attributes/AttributeData.cs#L521), [VisualBasicAttributeData.DecodeGuidAttribute](https://github.com/dotnet/roslyn/blob/Visual-Studio-2017-Version-15.9/src/Compilers/VisualBasic/Portable/Symbols/Attributes/AttributeData.vb#L470)). Regardless, the expected format of the string is part of the semantics of `GuidAttribute`, because the CLR must also be able to parse it. It is therefore correct to document it here.
---
#### Document Details
⚠ *Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.*
* ID: fdfc4ab7-f087-b16e-81f6-6b0e807ea80e
* Version Independent ID: 1e34a01f-4773-ace7-05d1-645b292c038a
* Content: [GuidAttribute Class (System.Runtime.InteropServices)](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.guidattribute?view=netframework-4.7.2)
* Content Source: [xml/System.Runtime.InteropServices/GuidAttribute.xml](https://github.com/dotnet/dotnet-api-docs/blob/master/xml/System.Runtime.InteropServices/GuidAttribute.xml)
* Product: **dotnet-api**
* GitHub Login: @rpetrusha
* Microsoft Alias: **ronpet**
Contributor guide
Assessment
This issue has not been assessed yet.