The input is not a valid Base-64 string
The exact reason you are getting this type of error is because it's not a valid Base64 string, instead as already mentioned, it's a Guid; and not a valid Guid at that.
First you can check if you even have a valid Base64 string by trying to convert it.
public static bool StringIsBase64(string myString)
{
Span<byte> buffer = new Span<byte>(new byte[myString.Length]);
return Convert.TryFromBase64String(myString, buffer , out int bytesParsed);
}
Now if you call this function and it succeeds, then we would assume you do have a valid Base64 string, otherwise a conversion error would occur.
Your call can now look like this:
string id = "59216167-f9c0-4b1b-b1db-1babd1209f10@ABC";
var bytes;
if (StringIsBase64(id))
{
bytes = Convert.FromBase64String(id);
}
Something else I would like to address that none of the other answers addressed, is the input is not valid for even a Guid. A GUID is a 128-bit integer (16 bytes) and that string isn't valid.
You actually would receive the error:
Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
The characters @ABC at the end of the string are causing this, if these are removed then we have an actual valid Guid.