Hi,
I keep getting the error Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) when i try to make a guid.
string entryNum = Convert.toString(entryNo);
Guid key = new Guid(entryNum); Hi,
I keep getting the error Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) when i try to make a guid.
string entryNum = Convert.toString(entryNo);
Guid key = new Guid(entryNum); The exception is coming from the Guid(string) constructor, which only accepts specific textual GUID formats. In addition to the classic 8-4-4-4-12 form, .NET recognizes format specifiers N, D, B, P, and X (e.g., 32 digits with no dashes for N, braces for B, parentheses for P, or the X hex tuple). That is why passing an arbitrary number or a name string fails; it is not a GUID in any accepted format. was on the right track; here are the exact formats .NET expects. Guid.ToString formats. If you need to parse/validate a string that should already be a GUID, prefer the safe parsers: Guid.Parse/TryParse.
Example: validate user input without throwing exceptions.
var text = inputText.Trim();
if (Guid.TryParse(text, out var id))
{
// use id
}
else
{
// handle invalid input
} On converting a name like "ben" into a GUID: as noted, GUIDs are meant to be opaque identifiers, not human-meaningful encodings. If you truly need a deterministic mapping from a name to a GUID, use a name-based UUID algorithm (RFC 9562 v5) with a fixed namespace (for example, the DNS namespace). That produces the same GUID for the same name every time, but do not use it for security tokens because v5 relies on SHA-1. See the UUID v5 rules and security notes here: RFC 9562. For database keys that sort better, modern .NET (9+) also offers timestamp-ordered GUIDs via Guid.CreateVersion7(). Details: What’s new in .NET 9 - System.Guid.
Jump to Post— kvprajapati 1,826You have pass a string which contains - dddddddddddddddddddddddddddddddd -or- Groups of 8, 4, 4, 4, and 12 digits with hyphens between the groups.
Take a look at - http://msdn.microsoft.com/en-us/library/96ff78dc%28v=VS.90%29.aspx
You have pass a string which contains - dddddddddddddddddddddddddddddddd -or- Groups of 8, 4, 4, 4, and 12 digits with hyphens between the groups.
Take a look at - http://msdn.microsoft.com/en-us/library/96ff78dc%28v=VS.90%29.aspx
thanks i understand that now but is there a way to covert a string to a guid? i.e the string name = ben i would like to make a guid representing that.
That's not the purpose of Guid, I think.
Guid.NewGuid() creates a unique identifier.
Thanks that worked didn't even know I could do that.
Thanks Again,
Jordan
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.