mshtml.HTMLDocumentClass doc = (mshtml.HTMLDocumentClass)IE.Document;
object script= doc.Script;
object[] args = { FirstArgument , "FrameContent", "tree.aspx", "FrameNav" };
script.GetType().InvokeMember("ZweiFrames",
System.Reflection.BindingFlags.InvokeMethod,
null, script,args);
Marshal.ReleaseComObject(script);
I used the above code to execute java script and getting an error.(Exception has been thrown by the target of an invocation) ( inner Exception : Insufficient memory to continue the execution of the program).
Please help me on this..
Thanks in advance..
Unni.
Have you checked ZweiFrames js function - may be there is issue in that function with arguments supplied by you?
BTW, yet another way to execute javascript function can be something like
HTMLWindow2 iHtmlWindow2 = (HTMLWindow2) doc.Script ;
iHtmlWindow2.execScript( "functionName(param1);" , "javascript" );
This is of course assuming that your parameters can be represented in a string form.
Related
I'm waaaay above my level of understanding here but have a simple request to change the sort order of data in a .NET datagrid. The system seems to use SubSonic to do the database queries, so there's a level of abstraction which I just don't understand and can't seem to guess at ;).
There is a line under the gridview control in the .aspx file like this:
<asp:ObjectDataSource ID="odsCsvReport" runat="server" SelectMethod="FetchAll" TypeName="WFlower.CsvReportController">
</asp:ObjectDataSource>
I've searched the project for 'CsvReportController' and there is a file in App_Code called 'CsvReportController.cs' in which there's a class like this:
[DataObjectMethod(DataObjectMethodType.Select, true)]
public CsvReportCollection FetchAll()
{
CsvReportCollection coll = new CsvReportCollection();
Query qry = new Query(CsvReport.Schema);
//qry.OrderDesc("CsvReportID");
coll.LoadAndCloseReader(qry.ExecuteReader());
return coll;
}
Now, I've just no idea how to get this data to be sorted by the 'CsvReportID' field in descending order (currently it's ascending).
Can anyone shed any light on this. Like I say, I'm in too deep here but it should be such a minor thing to do I'm determined to get to the bottom of it!
Thanks folks!
EDIT:
Okay, so as per #Mike Walsh's comment below, I tried this instead:
var qry = new Select().From(CsvReport.Schema);
qry.OrderDesc(new [] {CsvReport.Columns.AssignedToID});
return qry.ExecuteAsCollection<CsvReportCollection>();
Now however, this throws a completely different error elsewhere:
Violation of PRIMARY KEY constraint 'PK__OrdersToDelete__245EFE8C'. Cannot insert duplicate key in object 'dbo.OrdersToDelete'.
The statement has been terminated.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Violation of PRIMARY KEY constraint 'PK__OrdersToDelete__245EFE8C'. Cannot insert duplicate key in object 'dbo.OrdersToDelete'.
The statement has been terminated.
Source Error:
Line 187: //Do database management.
Line 188: int removedUsers = SPs.Hg_DeleteInactiveUsers(14).Execute();
Line 189: int removedOrders = SPs.Hg_DeleteInactiveOrders(14).Execute();
Line 190: }
Can't remember the exact differences in 2.1-2.2-2.3 but will this compile for you?
var qry = new Select().From(CsvReport.Schema);
qry.OrderDesc(new [] {CsvReport.Columns.AssignedToID});
return qry.ExecuteAsCollection<CsvReportCollection>();
I'm currently trying to implement an automated bug reporter for a Flex application, and would like to return error messages to a server along with the function/line number that caused the error. Essentially, I'm trying to get the getStackTrace() information without going into debug mode, because most users of the app aren't likely to have the debug version of flash player.
My current method is using the UncaughtErrorEvent handler to catch errors that occur within the app, but the error message only returns the type of error that has occurred, and not the location (which means it's useless). I have tried implementing getStackTrace() myself using a function name-grabber such as
private function getFunctionName (callee:Function, parent:Object):String {
for each ( var m:XML in describeType(parent)..method) {
if ( this[m.#name] == callee) return m.#name;
}
return "private function!";
}
but that will only work because of arguments.callee, and so won't go through multiple levels of function calls (it would never get above my error event listener).
So! Anyone have any ideas on how to get informative error messages through the global
error event handler?
EDIT: There seems to be some misunderstanding. I'm explicitly avoiding getStackTrace() because it returns 'null' when not in debug mode. Any solution that uses this function is what I'm specifically trying to avoid.
Just noticed the part about "I don't want to use debug." Well, that's not an option, as the non-debug version of Flash does not have any concept of a stack trace at all. Sucks, don't it?
Not relevant but still cool.
The rest is just for with the debug player.
This is part of my personal debug class (strangely enough, it is added to every single project I work on). It returns a String which represents the index in the stack passed -- class and method name. Once you have those, line number is trivial.
/**
* Returns the function name of whatever called this function (and whatever called that)...
*/
public static function getCaller( index:int = 0 ):String
{
try
{
throw new Error('pass');
}
catch (e:Error)
{
var arr:Array = String(e.getStackTrace()).split("\t");
var value:String = arr[3 + index];
// This pattern matches a standard function.
var re:RegExp = /^at (.*?)\/(.*?)\(\)/ ;
var owner:Array = re.exec(value);
try
{
var cref:Array = owner[1].split('::');
return cref[ 1 ] + "." + owner[2];
}
catch( e:Error )
{
try
{
re = /^at (.*?)\(\)/; // constructor.
owner = re.exec(value);
var tmp:Array = owner[1].split('::');
var cName:String = tmp.join('.');
return cName;
}
catch( error:Error )
{
}
}
}
return "No caller could be found.";
}
As a side note: this is not set up properly to handle an event model -- sometimes events present themselves as either not having callers or as some very weird alternate syntax.
You don't have to throw an error to get the stack trace.
var myError:Error = new Error();
var theStack:String = myError.getStackTrace();
good reference on the Error class
[EDIT]
Nope after reading my own reference getStackTrace() is only available in debug versions of the flash player.
So it looks like you are stuck with what you are doing now.
Am running asp.net application with access database using gridview application..while running i got the run time error as
Object reference not set to an instance of an object.
Line 41: RadioButtonList rblGender = (RadioButtonList)GridView1.Rows[e.RowIndex].FindControl("rbGenderEdit");
Line 42:DropDownList ddlStatus = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlStatusEdit");
Line 43:SqlDataSource1.UpdateParameters["Sex"].DefaultValue = rblGender.SelectedValue;
Line 44:SqlDataSource1.UpdateParameters["MaritalStauts"].DefaultValue = ddlStatus.SelectedValue;
Line 45: }
I got this error specially in line 43..
So rblGender.SelectedValue or rblGender is null...
Perhaps the problen is with rblGender
Make assignment as follows:
RadioButtonList rblGender = GridView1.Rows[e.RowIndex].FindControl("rbGenderEdit") as RadioButtonList;
And then check for nullability:
if (rblGender == null)
{
//show error
}
RadioButtonList rblGender = (RadioButtonList)GridView1.Rows[e.RowIndex].TemplateControl.FindControl("rbGenderEdit");
if it is in template field.
it can't find rbGenderEdit.
When you have a runtime error like this one, you should use your debugger to actually see what is going on behind the scene. Just put your breakpoint at the line 43 for instance, run your program in debug mode and start investigate to see what object has a null reference and try to fix it.
For instance take a look at the line 41, rblGender might be null...
EDIT
You must check if the objects that you are manipulating are null, this is part of the defensive programming techniques.
In your example, as others have said you can do it this way:
if(rblGender == null) {
// If you are running your program with a console
// Otherwise you should display this anywhere you can or in a log file.
Console.WriteLine("rblGender is null");
}
else if(rblGender.SelectedValue == null) {
Console.WriteLine("rblGender.SelectedValue is null");
}
Run your program and check what is being written! This is not going to solve your problem, but it is just going to tell you where your null reference is which will help you figure out what should be fixed!
But as I said earlier you can also debug your program properly by putting a breakpoint (you know the red ball when you click on the side of the window) at the line 43, and then run your program in debug mode! When the runtime error will fireup you will be able to check whether rblGender or rblGender.SelectedValue is null.
Also, from a more general point of view, checking your object against null references will prevent your application from crashing suddenly by managing the case where an objet might have a null reference at any given time. For instance you can say:
if(my_object is null)
{
myValue = "default";
}
else
{
myValue = my_objet.getValue();
}
This is just an example it could be done in a better way, using exceptions (try/catch/finally) for instance but the general idea is: check against null references!
I have used this code for extracting urls from web page.But in the line of 'foreach' it is showing
Object reference not set to an instance of an object
exception. What is the problem? how can i correct that?
WebClient client = new WebClient();
string url = "http://www.google.co.in/search?hl=en&q=java&start=10&sa=N";
string source = client.DownloadString(url);
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(source);
foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//a[#href and #rel='nofollow']"))
{
Console.WriteLine(link.Attributes["href"].Value);
}
First, you should look up the NullReferenceException in the documentation. It says
The exception that is thrown when there is an attempt to dereference a null object reference.
This means you did the equivalent of
SomeClass reference = null;
reference.Method(); // or reference.Property;
Next, look at the line of code that has the error and figure out what you are derefencing:
foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//a[#href and #rel='nofollow']"))
doc.DocumentNode
doc.DocumentNode.SelectNodes
So either doc is null, or doc.DocumentNodes is null. Since you just assigned a new instance of HtmlDocument to doc, doc can't be the problem. That implies that you loaded an empty document, such that there is no doc.DocumentNode.
Check before the loop to see if doc.DocumentNode is null.
Which line is the exception being thrown from; the actual foreach line, or the contents of the loop?
Probably the easiest method to deal with this one is to use the debugger - pop a breakpoint in front of the foreach, and when the runtime pauses, inspect the contents of the various variables, such as link, doc.DocumentNode, etc. If link is non-null, then check whether link.Attributes["href"] is, and so on.
Whenever I debug my AIR app it keeps suspending at a certain line of code...it doesn't give me a reason why, it just says Main Thread (Suspended) No error, no breakpoint at this location either. If I comment out the code so that, that line does not execute, it just does the same thing on a different line of code.
I have no clue why.... What should I do?
Thanks!!
Here is the function it happens in:
public function update (): void
{
dispatchEvent ( new Event ( EVENT_UPDATE_DOWNLOAD_STARTED ) );
var request: URLRequest = new URLRequest ( _newVersionUrl );
urlStream = new URLStream();
updateFileData = new ByteArray();
urlStream.addEventListener ( Event.COMPLETE, streamDownloadComplete );
urlStream.addEventListener ( ProgressEvent.PROGRESS, streamDownloadProgress );
urlStream.addEventListener ( IOErrorEvent.IO_ERROR, versionCheckIOErrorHandler );
urlStream.load(request);
}
this is the line it suspends on:
updateFileData = new ByteArray();
updateFileData is defined outside the function like so:
protected var updateFileData: ByteArray;
I should mention...this code is the code that Updates the version of air..could this be suspending because its trying to update while in adl.exe?
Thanks
Are you using FlexBuilder?
If you are, have you made sure there isn't a breakpoint set somewhere in your SDK source (I sometimes do this by mistake)?
Try checking, via the Debugging profile (Window > Perspective > Flex Debugging), the the Breakpoints view to see whether there's anything in there you don't recognize.
Also, when you're hung up, try stepping through the code (e.g., using F5 or F6) to see if that helps you figure out where the debugger's stopped.
Not 100% sure, because you're not hitting the error but - This might be an issue caused because the docs say you can't do the update while in the debugger:
When testing an application using the
AIR Debug Launcher (ADL) application,
attempting to update the application
results in an IllegalOperationError
exception.
This is from the livedocs.