我的页面加载中有这行代码。
string sId = Request["sId"];
//couple of more initializations
if (!string.IsNullOrEmpty(sId))
{
Guid GuidThingId = Guid.Parse(sId); //line 73
//method continues.
在我的生产日志中,对于某些用户,我在第 73 行看到 Null 异常。 未将对象引用设置为对象的实例。
知道发生了什么吗?
-编辑- 通过查看 $Guid.Parse$ 我发现它只能返回低于异常的值。
// Exceptions:
// System.ArgumentNullException:
// input is null.
//
// System.FormatException:
// input is not in a recognized format.
//
// System.Exception:
// An internal type conversion error occurred.
最佳答案
使用 Guid.TryParse 或 Guid.TryParseExact 进行尝试。如果您的示例正确,您的错误可能是解析内部的,并且您的字符串可能不是有效的 Guid。
关于asp.net - 你调用的对象是空的。在 Guid.Parse 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32979547/