asp.net - 你调用的对象是空的。在 Guid.Parse 上

标签 asp.net c web guid

我的页面加载中有这行代码。

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/

相关文章:

c - 为什么这个递增 uint8_t 的代码包含 `& 0xFF` ?

c - 具有特定要求的纯C通用双向哈希表

java - 使用Java和OpenGL绘制3D树有哪些方法?

jquery - 当字段为空时,远程属性不会触发

c# - 使用 ASP.NET、C# 和 JSON 将事件添加到完整日历

html - 网页 HTML/CSS 上的并排文本

java - 为什么我的 MDC SLF4J 中的两个请求会出现重复的 ID?

web -::shadow 和/deep/的替代品是什么?

c# - .net SiteMap菜单显示

c# - ASP.Net-Core 中的自定义身份验证