Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 调试:Microsoft JScript运行时错误_C#_Asp.net_Debugging_Error Handling - Fatal编程技术网

C# 调试:Microsoft JScript运行时错误

C# 调试:Microsoft JScript运行时错误,c#,asp.net,debugging,error-handling,C#,Asp.net,Debugging,Error Handling,我非常需要调试帮助,已经被这个错误困扰了6天了 我在ASp.net应用程序中遇到的错误是: Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modifi

我非常需要调试帮助,已经被这个错误困扰了6天了

我在ASp.net应用程序中遇到的错误是:

Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.
Details: Error parsing near '<script type='text/j'.
经过数小时的调试,我发现这一行导致了错误:

CollyReportServiceResponse ValResponse = Col_ValSub.validateReport(ServiceReq);
经过6天的调试和挫折之后,我发现一些记录会导致此问题,而其他记录不会出现在旧版本的代码中,但在新版本中,所有记录都会导致此错误,因此必须对数据库中的数据进行处理,这意味着代码中的某些方法的行为与null不同,但我无法确切找出问题所在是因为我的应用程序有3万行代码

在四处搜索并尝试各种解决方案后,下面的2个不是我问题的解决方案

forums.asp.net/t/1357862.aspx

我想说的是,我已经很难处理这个应用程序了,因为它是由其他程序员编写的,而这些程序员现在已经很久没有留下任何文档或注释的意大利面代码了

我并没有编写这段代码,但过去的其他程序员已经给出了响应。请编写代码:

   private void MessageBox(string msg)
    {
        if (!string.IsNullOrEmpty(msg))
        {
            Global.tmpmsg = msg;
            msg = null;
        }
        Response.Write("<script type=\"text/javascript\" language=\"javascript\">");
        Response.Write("window.open('ErrorPage.aspx?msg=" + "','PopUp','screenX=0,screenY=0,width=700,height=340,resizable=1,status=no,scrollbars=yes,toolbars=no');");
        Response.Write("</script>");

    }
private void消息框(字符串消息)
{
如果(!string.IsNullOrEmpty(msg))
{
Global.tmpmsg=msg;
msg=null;
}
回答。写(“”);
Response.Write(“window.open('ErrorPage.aspx?msg=“+”,'PopUp','screenX=0,screenY=0,width=700,height=340,resizeable=1,status=no,scrollbars=yes,toolbars=no');
回答。写(“”);
}
这是另一种方法:

        Response.Write("<script type=\"text/javascript\" language=\"javascript\">");
        Response.Write("alert('No search resuls were found');");
        Response.Write("</script>"); 
Response.Write(“”);
Write(“警报(‘未找到搜索结果’);”;
回答。写(“”);
或者这个:

if (!string.IsNullOrEmpty(msg))
{
    Global.tmpmsg = msg;
    Response.Write("<script type=\"text/javascript\" language=\"javascript\">");
    Response.Write("window.open('ErrorPage.aspx?msg=" + "','PopUp','screenX=0,screenY=0,width=700,height=340,resizable=1,status=no,scrollbars=yes,toolbars=no');");
    Response.Write("</script>");
}
if(!string.IsNullOrEmpty(msg))
{
Global.tmpmsg=msg;
回答。写(“”);
Response.Write(“window.open('ErrorPage.aspx?msg=“+”,'PopUp','screenX=0,screenY=0,width=700,height=340,resizeable=1,status=no,scrollbars=yes,toolbars=no');
回答。写(“”);
}
在Jrummel的评论之后,我将此添加到代码中,然后什么也没发生

private void MessageBox(string msg)
{/*
    if (!string.IsNullOrEmpty(msg))
    {
        Global.tmpmsg = msg;
        msg = null;
    }
    Response.Write("<script type=\"text/javascript\" language=\"javascript\">");
    Response.Write("window.open('ErrorPage.aspx?msg=" + "','PopUp','screenX=0,screenY=0,width=700,height=340,resizable=1,status=no,scrollbars=yes,toolbars=no');");
    Response.Write("</script>");
    */
// Define the name and type of the client scripts on the page.
String csname1 = "PopupScript";
Type cstype = this.GetType();

// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;

// Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered(cstype, csname1))
{
    String cstext1 = "<script type=\"text/javascript\" language=\"javascript\">" + " " + "window.open('ErrorPage.aspx?msg=" + "','PopUp','screenX=0,screenY=0,width=700,height=340,resizable=1,status=no,scrollbars=yes,toolbars=no');" + " " + "</script>";
  cs.RegisterStartupScript(cstype, csname1, cstext1, false);
}



}
private void消息框(字符串消息)
{/*
如果(!string.IsNullOrEmpty(msg))
{
Global.tmpmsg=msg;
msg=null;
}
回答。写(“”);
Response.Write(“window.open('ErrorPage.aspx?msg=“+”,'PopUp','screenX=0,screenY=0,width=700,height=340,resizeable=1,status=no,scrollbars=yes,toolbars=no');
回答。写(“”);
*/
//定义页面上客户端脚本的名称和类型。
字符串csname1=“popuscript”;
类型cstype=this.GetType();
//从Page类获取ClientScriptManager引用。
ClientScriptManager cs=Page.ClientScript;
//检查启动脚本是否已注册。
如果(!cs.isstartupscript已注册(cstype,csname1))
{
字符串cstext1=“+”+”窗口。打开('ErrorPage.aspx?msg=“+”,'PopUp','screenX=0,screenY=0,宽度=700,高度=340,可调整大小=1,状态=no,滚动条=yes,工具栏=no');“+”“+”;
RegisterStartupScript(cstype,csname1,cstext1,false);
}
}

不要使用
Response.Write()
。 相反,请创建一个并将其添加到页面中

用于将脚本添加到页面。以下是MSDN中的一个示例:

// Define the name and type of the client scripts on the page.
String csname1 = "PopupScript";
Type cstype = this.GetType();

// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;

// Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered(cstype, csname1))
{
  String cstext1 = "alert('Hello World');";
  cs.RegisterStartupScript(cstype, csname1, cstext1, true);
}

经过2周的调试和2天的强制执行,我发现了错误:

在我拥有的一个800 DB列中,有一个空/不正确的值。这个值与我的ASP.NET代码中的150个方法中的一个方法发生反应,导致出现JavaScript错误,即使Response.Write()不是问题所在。我没有找到哪个方法对这个值有反应,但我找到了解决方案,就是在列记录上输入一个有效值

程序员如何使用暴力来发现问题:

在我的例子中,经过长时间的调试,我采集了一条工作记录的样本和另一条错误引导记录的样本。一旦我做到了这一点,我就

DELETE FROM tablename WHERE UniqueColID= unique identifier for the error causing record
然后我做了:

INSERT INTO tablename ([uniqueIdentifier],[ column 2],[column 3]) SELECT @UniqueIdentifierofErrorCausingRecord, column2, [column3] FROM TableName WHERE [uniqueIdentifier]=@UniqueIdentifierForWorkingRecord;
第一条语句所做的是删除非工作记录,然后第二条语句使用工作记录的相同列值重新插入该记录,但使用非工作记录的唯一标识符。通过这种方式,我可以遍历每个表,找出导致错误的表,然后我可以确定该表的哪一列是问题所在


我的例子中的具体问题是DateTime.TryParse(),因为表列值以不正确的格式插入。。代码在其中一个方法中执行了字段填充,而没有使用DateTime.Parse方法进行尝试和捕获。。。。经过一些测试,似乎连try/catch都无法发现这个错误,因为它是一个javascript错误。

我看不出错误和代码片段之间有任何关系。
标记在哪里?这一行没有显示任何js注册,并且您的错误与javascript相关。您需要向我们展示更多相关的代码。错误提到了
Response.Write()
,您在哪里使用过它吗?@jrumell能否请您再详细说明一下,我对ASP.net或任何这些Response.Write方法都不是很有经验。@jrumell在编辑后我更新了帖子,现在似乎什么也没有发生,这也不是你想要的行为。如果你看一下你生成的html,你可能会看到两组脚本标签包装着你的脚本,还有另一个脚本错误。
RegisterStartupScript()
中的最后一个参数指示运行时是否将添加周围的
标记。因此,您需要将其更改为false,或者从脚本字符串中删除脚本标记。@jrumell,即使我将其更改为false,也不会发生任何情况。让我们
INSERT INTO tablename ([uniqueIdentifier],[ column 2],[column 3]) SELECT @UniqueIdentifierofErrorCausingRecord, column2, [column3] FROM TableName WHERE [uniqueIdentifier]=@UniqueIdentifierForWorkingRecord;