Debugging: Microsoft JScript runtime error - c#

I am desperately in need of debugging help, been stuck at this error for 6 days now.....
the error I get in my ASp.net app is :
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'.
Below is the relevant code snippet,
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;
}
After hours of debugging I found this line to be causing the error:
CollyReportServiceResponse ValResponse = Col_ValSub.validateReport(ServiceReq);
After 6 days of debugging and frustration I found that SOME records cause this issue and others dont in OLDER versions of the code but in new version ALL of the records lead to this error so it has to do something with the data in the DB which means SOME method in the code behaves differently to nulls but I cant find out exactly what the issue is because my app is 30k lines of code
after searching around and trying various solutions, the below 2 are not the solutions to my issue.
forums.asp.net/t/1357862.aspx
http://www.vbforums.com/showthread.php?t=656246
I want to mention that I am already having a difficult time dealing with this application because it was written by other programmers that are now long gone leaving behind non-documented or commented spaghetti code.
I did not code this but other programmers from past have put Response.Write in code:
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>");
}
This one is in another method:
Response.Write("<script type=\"text/javascript\" language=\"javascript\">");
Response.Write("alert('No search resuls were found');");
Response.Write("</script>");
Or This:
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>");
}
After Jrummel`s comment I added this to code and then nothing at all happened.
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);
}
}

I have found the error after 2 weeks of debugging and 2 days of Brute Forcing:
In one of the 800 DB columns that I have there was a null/improper value. This value reacted with one of the 150 methods in my ASP.NET code in such a way as to present a JavaScript error even though Response.Write() was NOT the issue. I have not found which method it was that reacted to this value but I have found the solution which is to simply input a valid value on the column record..
How a programmer can brute force to find the issue:
In my case after long days of debugging I took a sample of one working record and another sample of an error leading record. Once I had achieved this, I used
DELETE FROM tablename WHERE UniqueColID= unique identifier for the error causing record
Then I did:
INSERT INTO tablename ([uniqueIdentifier],[ column 2],[column 3]) SELECT #UniqueIdentifierofErrorCausingRecord, column2, [column3] FROM TableName WHERE [uniqueIdentifier]=#UniqueIdentifierForWorkingRecord;
What the first statement does is delete the non working record then the 2nd statement reinserts that record with identical column values of the working record but with the UniqueIdentifier of the Non working record. This way I can go through each table to find which table is causing the error and then I can pinpoint which column of that table is the issue.
The specific issue in my case was DateTime.TryParse() because a table column value was inserted in improper format.. The code performed field population in one of the methods without a try and catch using the DateTime.Parse method.... After some testing it seems even a try/catch is not able to pick this error up as it is a javascript error..

Don't use Response.Write().
Instead, create a LiteralControl and add it to the page.
Use ClientScriptManager to add scripts to the page. Here's an example from 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);
}

Related

handle error on Microsoft.AnalysisServices update method

I am updating dimension definition in 'Data Source View'. Doing it using C# code inside SSIS script task.
Here is simplified C# code:
DataSourceView ASDataSourceView;
//DataSourceView inherits from MajorObject
ASDataSourceView.Schema.Tables["DimTable"].ExtendedProperties["QueryDefinition"] = "SELECT * FROM ufc.TableWithData";
ASDataSourceView.Update();
I need to handle error which may appear during Update() method.
I thought that usual approach with try catch will work but it seems it is not a case.
I need to get an xml response object somehow and then check if it is empty(no error) or parse it and build further logic.
I was trying to read Microsoft documentation but have no idea how to do it.
XmlaWarningCollection Class
When I run update xml statement in SSMS I get the following messages:
when update succeed:
<return xmlns="urn:schemas-microsoft-com:xml-analysis">
<root xmlns="urn:schemas-microsoft-com:xml-analysis:empty" />
</return>
when update fails(fails because of syntax error not logic which is also not very correct from simulation point of view):
XML parsing failed at line 9597, column 63: The name in the end tag of the element must match the element type in the start tag.
Run complete
Can anybody help?
I think I finally found solution:
First you need to enable CaptureXML option;
ServerName.CaptureXml = true;
Second run Update with XmlaResultCollection option:
UpdateOptions uo = default(UpdateOptions);
UpdateMode om = default(UpdateMode);
XmlaWarningCollection xm = null;
ASDataSourceView.Update(uo, om, xm);
Third you execute update statement:
XmlaResultCollection resultCollection = ServerName.ExecuteCaptureLog(false, false);
After that I was able to parse resultCollection object:
String ErrorMessages = String.Empty;
if (resultCollection.ContainsErrors) {
ErrorMessages += $"Errors occured in cube {ConnectionString.CatalogName}:" + Environment.NewLine;
foreach (AS.XmlaResult result in resultCol) {
foreach (object error in result.Messages) {
if (error.GetType() == typeof(AS.XmlaError))
ErrorMessages += "ERR: " + ((AS.XmlaError)error).Description + Environment.NewLine;
else if (error.GetType() == typeof(AS.XmlaWarning))
ErrorMessages += "WARN: " + ((AS.XmlaWarning)error).Description + Environment.NewLine;
}
}
throw new Exception(ErrorMessages);
}

Cannot assign to GetDropDownValues because it is a method group?

I have a question regarding the code below, am trying to get the dropdown values from a generic query, passing the field and table name. I am getting the error Cannot assign to GetDropDownValues because it is a method group and not sure how to resolve? Can anyone shed some light? Thanks in advance...
public static DataTable GetDropDownValues(string pstrConString_Mfg, string pstrTableName, string pstrFieldName, string pstrField = "")
{
string strSQL;
DataTable dtRetTable;
try
{
strSQL = "SELECT DISTINCT " + pstrFieldName;
if (pstrField != "")
{
strSQL = strSQL + " , " + pstrField;
}
strSQL = strSQL + " FROM " + pstrTableName + " ORDER BY " + pstrFieldName;
dtRetTable = ExecuteDataTable(pstrConString_Mfg, CommandType.Text, strSQL);
if (dtRetTable != null)
{
if ((dtRetTable.Rows.Count == 0))
{
GetDropDownValues = new DataTable(); <--error
}
else
{
dtRetTable.BeginLoadData();
dtRetTable.Rows.InsertAt(dtRetTable.NewRow, 0);
dtRetTable.EndLoadData();
dtRetTable.AcceptChanges();
GetDropDownValues = dtRetTable;
}
}
else
{
GetDropDownValues = new DataTable();
}
}
catch (Exception ex)
{
throw ex;
}
}
--==================================================
Also am getting error on line ' dtRetTable.Rows.InsertAt(dtRetTable.NewRow, 0);'
cannot convert from 'method group' to 'DataRow'. I am assuming it is related to above error?
Where you wrote GetDropDownValues = dtRetTable; and GetDropDownValues = new DataTable(); looks like older Visual Basic (also Visual Basic for Applications, VBA) syntax for having a function return a value.
With C# (and C, C++, Java, JavaScript and a lot of others) you need to return a value and not assign it to the function name.
Do this instead:
return dtRetTable;
and
new DataTable();
Edit to address your other question...
For the error on the line dtRetTable.Rows.InsertAt(dtRetTable.NewRow, 0) doing as #Ed Plunkett suggested will fix this problem. As you said you are converting older code to work in C#, it will be easy to forget to add the trailing brackets () as required by C# but the error message you get of method group - Well, I've only ever seen it when I forget to put the brackets in, so it will be easier for you to understand what is going on.
And finally, do not catch Exceptions unless you intend to do something about the exception there and then. You should always catch the Exception in your Interface methods so you can show a nicer message to your users and prevent the app from crashing out.
Where you wrote throw ex;, it would be better to just write throw or if you are willing, remove the try/catch block entirely. When you throw ex you will destroy the correct StackTrace which is essential for debugging and figuring out what the problem is. There is lots of information (and a lot more in-depth) on this in StackOverflow as well as the rest of the Web.
Happy translating, and remember we love to help those who make an attempt to help themselves first.

Implemented error logging with crazy results

I have added the ability for us to log errors to our database for all HTTPExceptions. Once this was pushed live we logged about 10,000 in the span of around 15 minutes. I have to assume these errors were happening all the time, but since they were not critical errors the user didn't notice anything.
Here is the code in my Global.asax
protected void Application_Error(object sender, EventArgs e)
{
Exception exception = Server.GetLastError();
if (exception is HttpException)
{
var httpException = exception as HttpException;
if (httpException.GetHttpCode() == 404)
{
// Page not found error
Response.StatusCode = 404;
using (MyEntities db = new MyEntities())
{
ErrorLog error = new ErrorLog();
error.Date = DateTime.Now;
error.Type = httpException.GetHttpCode().ToString();
error.Message = httpException.Message;
error.Source = httpException.Source;
error.StackTrace = httpException.StackTrace;
error.TargetSite = Request.Url.ToString();
error.Browser = Request.Browser.Browser + "(" + Request.Browser.Type + ")" + "v" + Request.Browser.Version;
error.IP = Request.ServerVariables["REMOTE_ADDR"];
//db.ErrorLogs.Add(error);
//db.SaveChanges();
}
}
else if (httpException.GetHttpCode() == 500)
{
// Server Error
Response.StatusCode = 500;
using (MyEntities db = new MyEntities ())
{
ErrorLog error = new ErrorLog();
error.Date = DateTime.Now;
error.Type = httpException.GetHttpCode().ToString();
error.Message = httpException.Message;
error.Source = httpException.Source;
error.StackTrace = httpException.StackTrace;
error.TargetSite = Request.Url.ToString();
error.Browser = Request.Browser.Browser + "(" + Request.Browser.Type + ")" + "v" + Request.Browser.Version;
error.IP = Request.ServerVariables["REMOTE_ADDR"];
//db.ErrorLogs.Add(error);
//db.SaveChanges();
}
}
else
{
// All Other Errors
Response.StatusCode = 500;
using (MyEntities db = new MyEntities ())
{
ErrorLog error = new ErrorLog();
error.Date = DateTime.Now;
error.Type = "999";
error.Message = httpException.Message;
error.Source = httpException.Source;
error.StackTrace = httpException.StackTrace;
error.TargetSite = Request.Url.ToString();
error.Browser = Request.Browser.Browser + "(" + Request.Browser.Type + ")" + "v" + Request.Browser.Version;
error.IP = Request.ServerVariables["REMOTE_ADDR"];
//db.ErrorLogs.Add(error);
//db.SaveChanges();
}
}
}
Out of the 10,000 errors we have logged only 50 of them were unique.
Here are examples of some of them
type Message
999 A potentially dangerous Request.Path value was detected from the client (:).
999 A potentially dangerous Request.Path value was detected from the client (>).
404 The controller for path '/images/favicon.ico' was not found or does not implement IController.
404 The controller for path '/Scripts/jquery-1.4.2.min.js' was not found or does not implement IController.
404 The controller for path '/Scripts/jquery-ui-1.8.5.custom.min.js' was not found or does not implement IController.
Now these seem like pretty silly errors. And from a user stand point this does not throw them to our custom 404 error page. So I am guessing they hit this error and are later redirected so they never see or notice they hit an error unless something is wrong with the code.
Anyone able to point me in the right direction to fix these if they are legitimate errors?
The last three 404 errors don't even make sense to me because they are not controllers and should not be treated like controllers ever.
These do look pretty harmless, or at least they're problably harmless. There are 2 separate issues here:
The first 2 errors come from someone having a ":" or ">" as part of their request's path. Possibly a url like "http://yoursite.com/stuff:here". This is something asp.net does to help prevent XSS attacks. Unless you have valid URLs that allow this, you probably want to leave it alone. However, if you want to check the errors, you can catch this exception by adding a check for HttpRequestValidationException. There are also some web.config changes you can make to allow these characters if they are necessary to your site's operation:
Getting "A potentially dangerous Request.Path value was detected from the client (&)"
As for the last 3, "The controller for path xxx ...". These are routing issues that only happen on IIS 7 and earlier (as well as the VS WebServer)
One that might work well for you is:
routes.IgnoreRoute("{*staticfile}", new { staticfile = #".*\.(css|js|gif|jpg|ico)(/.*)?" });

JScript runtime error in Sharepoint Webpart

I'm trying to design a webpart that looks at a list of news items, and initially prints all the rows in order by date. If the user selects a type of news item, then only those news items will be displayed (again, in order by date). The problem is that my webpart keeps throwing up this error when I try to debug it:
Microsoft JScript runtime error: Unknown runtime error
And this mess pops up behind it:
RTE.RteUtility.$1n = function($p0, $p1) {
if (RTE.RteUtility.isInternetExplorer() && $p0.tagName === 'TABLE') {
var $v_0 = document.createElement('DIV');
$v_0.innerHTML = '<table>' + $p1 + '</table>';
while ($p0.childNodes.length > 0) {
$p0.removeChild($p0.childNodes[0]);
}
RTE.RteUtility.$1E($v_0.firstChild, $p0);
}
else {
$p0.innerHTML = '<div>RTE</div>' + $p1;
$p0.removeChild($p0.firstChild);
}
}
The line: "$p0.innerHTML = 'RTE' + $p1" seems to be causing the problem. Well, otherwise, that's a really specific error message, thanks Microsoft. :/
The error seems to happen after CreateChildControls is called by NewsFeed.cs. My best theory right now is maybe something in NewsFeedUserControl.ascx.cs is causing an error, but as I'm a total neophyte at SharePoint I have no idea what that could possibly be. Is it because of this code in Page_Load?
protected void Page_Load(object sender, EventArgs e)
{
list = web.Lists["NewsFeedLI"];
query.Query = "<Where><IsNotNull><FieldRef Name='Headline' /></IsNotNull></Where></Query>" +
"<OrderBy<FieldRef Name='Article_x0020_Date' Ascending='True' /></OrderBy>";
SPListItemCollection result = list.GetItems(query);
foreach (SPListItem item in result)
{
newsList.Text = newsList.Text + item["Headline"].ToString() + Environment.NewLine;
newsList.Text = newsList.Text + item["Summary"].ToString() + Environment.NewLine + Environment.NewLine;
}
}
See, I don't know.
Try predefining the text that you return in your loop. If the web part looks OK with basic text (e.g. "Hello World") but not with more advanced values then that it where your problem lies.
You will want to ensure that you apply the appropriate encoding to any output you are rendering to the screen as this may be causing you issues.

Big websites not loading at all - error

I have created a web browser for windows phone 7. In that am saving the history of browsing also with title of that page. But due to this codes when i tried to load a somewhat big website like thinkdigit,etc. are not loading. At the same time if i delete that particular codes then no history is being recorded in the history page. It shows error for the below highlighted code - "An unknown error has occurred. Error: 80020006". I think its due to big site or else do i need to put milliseconds or what i have to do???
Thanks in advance for your hard work!!!
Below is the codes i have used for it-
private void browsers_Navigated(object sender,System.Windows.Navigation.NavigationEventArgs e)
{
pbarWebClient.Visibility = System.Windows.Visibility.Collapsed;
if (!fromHistory)
{
if (HistoryStack_Index < HistoryStack.Count)
{
HistoryStack.RemoveRange(HistoryStack_Index, HistoryStack.Count - HistoryStack_Index);
}
HistoryStack.Add(e.Uri);
if (!app.incognito)
{
********string title = (string)browsers[this.currentIndex].InvokeScript("eval", "document.title.toString()");********----->This is the error.
stream.WriteLine(title + ";" + e.Uri.ToString());
}
HistoryStack_Index += 1;
}
fromHistory = false;
navigationcancelled = false;
Stop.Visibility = Visibility.Collapsed;
}
I would expect that eval has been overridden or in some other way suppressed on the site(s) in question.
"80020006" is a javascript invocation error code. Simply assuming that a javascript method will be available and work in the same way on any site is not always going to be true.
Finally i got the suitable answer for my own question. Just replace the above codes with this-
if (!app.incognito)
{
Thread.Sleep(100);
Dispatcher.BeginInvoke(() =>
{
string title = (string)browsers[this.currentIndex].InvokeScript("eval", "document.title.toString()");
stream.WriteLine(title + ";" + e.Uri.ToString());
});
}

Categories