调试:Microsoft JScript运行时错误
作者:互联网
我迫切需要调试帮助,现在在此错误上停留了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'.
以下是相关的代码段,
CollyDataExchangeWebService Col_ValSub = new CollyDataExchangeWebService();
CollyReportServiceRequest ServiceReq = new CollyReportServiceRequest();
CollyReportServiceRequestData ServiceReqData = new CollyReportServiceRequestData();
ServiceReqData.AmendmentIndicatorSpecified = true;
ServiceReqData.AmendmentIndicator = false;
ServiceReqData.CollyReport = ColRep;
ServiceReq.ServiceRequestData = ServiceReqData;
ServiceReq.ServiceRequestHeader = ServiceHeader;
errValidate = null;
//btnOK.OnClientClick = "MSGShow()";
bool Valid = true;
string ErrMsgs = "";
if (((System.Web.UI.WebControls.Button)(sender)).CommandArgument == "Validate")
{
CollyReportServiceResponse ValResponse = Col_ValSub.validateReport(ServiceReq);
switch (ValResponse.ServiceResponseHeader.ServiceStatus)
{
case ServiceStatus.Successful:
btnOK.OnClientClick = "";
valHeader.Text = "Validation is Completed. No errors were found";
mlValPopup.Show();
break;
case ServiceStatus.ValidationErrors:
Valid = false;
ErrMsgs = ErrMsgs + _ValidationError(ValResponse);
ValBTN.Update();
mlValPopup.Show();
break;
case ServiceStatus.SystemError:
btnOK.OnClientClick = "";
Valid = false;
ErrMsgs = ErrMsgs + _SystemError(ValResponse);
ValBTN.Update();
mlValPopup.Show();
break;
}
经过数小时的调试,我发现此行引起了错误:
CollyReportServiceResponse ValResponse = Col_ValSub.validateReport(ServiceReq);
经过6天的调试和无奈之后,我发现某些记录会导致此问题,而其他记录在较旧的代码中则不会,但是在新版本中,所有记录均会导致此错误,因此它必须对数据库中的数据进行处理,这意味着代码中的某些方法的行为与null有所不同,但我无法确切找出问题所在,因为我的应用是3万行代码
经过四处搜寻并尝试各种解决方案后,以下2种问题都不是我的解决方案.
forums.asp.net/t/1357862.aspx
http://www.vbforums.com/showthread.php?t=656246
我想提到的是,我已经很难处理这个应用程序,因为它是由其他程序员编写的,这些程序员现在早已离开了未记录或注释过的意大利面条代码.
我没有编写此代码,但过去的其他程序员已将Response.Write放入代码中:
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>");
}
这是另一种方法:
Response.Write("<script type=\"text/javascript\" language=\"javascript\">");
Response.Write("alert('No search resuls were found');");
Response.Write("</script>");
或这个:
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>");
}
在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);
}
}
解决方法:
经过2周的调试和2天的蛮力强迫后,我发现了错误:
在我拥有的800个DB列之一中,有一个null / improper值.这个值与我的ASP.NET代码中的150种方法之一反应,以致即使出现Response.Write()都不是问题时也会出现JavaScript错误.我没有找到对这个值做出反应的方法,但是我找到了在列记录中简单输入有效值的解决方案.
程序员如何通过蛮力发现问题:
以我为例,经过长时间的调试,我从一个工作记录中抽取了一个样本,并从一个错误引导记录中获取了另一个样本.一旦做到这一点,我就用
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;
第一条语句执行的操作是删除非工作记录,然后第二条语句重新插入该记录,该记录具有与工作记录相同的列值,但具有非工作记录的UniqueIdentifier.这样,我可以遍历每个表以查找导致错误的表,然后确定该表的哪一列是问题所在.
在我的情况下,特定的问题是DateTime.TryParse(),因为以不正确的格式插入了表列值.代码使用一种方法执行字段填充,而没有使用DateTime.Parse方法进行尝试捕获.经过一些测试,看来即使是try / catch也无法拾取此错误,因为它是javascript错误.
标签:debugging,error-handling,asp-net,c 来源: https://codeday.me/bug/20191201/2078087.html