c# - 值不能为空。参数名称 : String

标签 c# exception handler request.querystring nul

请看下面的代码。它在 handler.asxh 中。

public void ProcessRequest(HttpContext context)
{
    context.Response.ContentType = "application/json";
    new RequestManagementFacade().PinRequest(Int32.Parse(context.Request.QueryString["requestId"]), (Boolean.Parse(context.Request.QueryString["isPinned"])));
}

这显示了以下错误:

Value cannot be null. Parameter name: String

当我检查上下文请求查询字符串时,有值被传递,但是,代码在这个阶段中断。

此处理程序将连接到业务逻辑层。

最佳答案

There is value being passed as i have checke dthe context request query string

我强烈怀疑你的诊断不正确。值(value)观不会神奇地消失——你需要质疑你的假设。虽然这很容易调试。我建议将您的代码更改为:

public void ProcessRequest(HttpContext context)
{
    context.Response.ContentType = "application/json";
    string requestId = context.Request.QueryString["requestId"];
    string isPinned = context.Request.QueryString["isPinned"];
    var facade = new RequestManagementFacade();
    facade.PinRequest(Int32.Parse(requestId), Boolean.Parse(isPinned));
}

然后真的很容易一步一步地找出正在发生的事情。

关于c# - 值不能为空。参数名称 : String,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13702212/

相关文章:

c# - 如何在 F# 中抛出带有有意义消息的异常?

java - 定制异常

android - 几秒钟后在 Webview 中加载 url

c# - 使用 StructureMap 注入(inject)自定义成员提供程序

C#:在不定义新类的情况下创建抽象类的实例

java - 将异常传递给该方法

android - 从 Thread 调用 Handler 会导致 NullPointerException

java - 几秒钟后移动到另一个 Activity - Activity 不是封闭类

c# - 如何以编程方式更改 Windows 注册表中的值?

java - 在 Javadoc 中使用多少 @throws