Convert.FromBase64String()无法正常运行

Cat*_*lMF -1 c# base64

在下面的示例中,为什么Convert.FromBase64String()不会抛出异常.当然应该抛出格式异常?

string s = "This is just a test string which we will test if it is base64";

bool isBase64 = false;

try
{
     byte[] b = Convert.FromBase64String(s);
     isBase64 = true;
}
catch(Exception ex)
{
      Console.WriteLine(ex.ToString());
      isBase64 = false;
}
Run Code Online (Sandbox Code Playgroud)

fej*_*oco 9

首先,每当您认为框架被破坏时,请再次思考,因为它很少出现,特别是对于这样一个基本和旧的功能.

这实际上是一个完全有效的base64字符串.空格是可选的并被忽略.然后你得到"Thisisjustateststringwhichwewilltestifitisbase64".长度恰好可以被4整除,它只包含字母和数字.你没有理由认为它是无效的.

  • [MSDN文档](http://msdn.microsoft.com/en-us/library/system.convert.frombase64string(v = vs.110).aspx) (2认同)