Showing posts with label thrown. Show all posts
Showing posts with label thrown. Show all posts

Saturday, March 24, 2012

Exceptions and javascript errors

If you have an updatepanel, and an exception is thrown during postback, a javascript error is generated. Is there any way that atlas could display the exception that was generated?

Not with the current release. We'll be adding some support for error handling.

What I am curious is why you'd want to show the exception on the server to the user. Exceptions really aren't meant for end users to see, given they have not much context to interpret them.


Well, it's nice for debugging purposes, I don't mean to necessarily show the error to an end user. Right now, as far as I can tell, the easiest way to see the exception that is generated is to temporarily turn off EnablePartialRendering.

Yes, the plan would be to make sure you can get the exception info, but the plan would probably not provide an out-of-the-box way to display it (you could do that if it makes sense for your app).

What I use right now for seeing exception info is my web development helper's http tracing (the response shows the exception info). Check outhttp://www.nikhilk.net/Projects.WebDevHelper.aspx.

Exception thrown from code inside an updatepanel is not handled by global.asax Application

Hi All

In the application I developed, I had the code to log the exceptions in Global.asax. This was working fine until I use Ajax update panel in the code behind of a few files.

When an exception happens in the code, called through update panel, Application_Error handler in the global.asax is never called.
Instead I can see an alert with the exception.message.

Is this a known issue? if so, is there a was to call the Application_Error automatically in case any exception thrown.

Thanks

Hi,

It's not a issue, but designed to work so.

If it's a asyncRequest, an custom error handler will be registered to handle any exception. The error message is encoded and returned in the internal error handler. And it's worth mentioning that this exception isn't swallowed and theoretically speaking, the appliction_error is able to fire.


Hi,

Thanks for the reply.

But the Application_Error event is not called.

I tried setting breakpoint in the function entry point and indused an Object Reference Is Nothing Errror within the code that is called through UpdatePanel. The breakpoint is not getting hit. Even in the test server, the errors are not getting logged. Is there any way, we can override the Ajax custom error handler or just make the Application_Error event to be called.


I used the following code, and it's able to trigger the Application_Error method.

<%@. Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { Label1.Text = DateTime.Now.ToString(); throw new Exception("custom exception"); }</script><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> </ContentTemplate> </asp:UpdatePanel> </div> </form></body></html>

Can you try it? Please let me know the result.


Hi

One more thanks for the reply.

I tried the code, the exception is getting thrown, but still the breakpoint in application_error is not being hit.


Can you simplify your app into a single page along with web.config that is able to reproduce the problem and mail it to me?

Hi Mr.Raymond Wen,

Many thanks for your continued support.

Below I post a simple "Not in use" page, for your understanding

<%@. Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> </script><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server"> <title>Partial-Page Update Error Handling Example</title></head><body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server" OnAsyncPostBackError="ScriptManager1_AsyncPostBackError"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:TextBox ID="TextBox1" runat="server" Width="39px"></asp:TextBox> / <asp:TextBox ID="TextBox2" runat="server" Width="39px"></asp:TextBox> = <asp:Label ID="Label1" runat="server"></asp:Label><br /> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="calculate" /> </ContentTemplate> </asp:UpdatePanel> </div> </form></body></html>
PartialClass _DefaultInherits System.Web.UI.PageProtected Sub Button1_Click(ByVal senderAs Object,ByVal eAs System.EventArgs)Try Throw New Exception("FOR TESTING")Finally End Try End SubEnd Class


GLOBAL.ASAX

'This code is not being called during an asyncronous postback'But this is called when a request is made directly without using UpdatePanel.Sub Application_Error(ByVal senderAs Object,ByVal eAs EventArgs)Dim exAs System.Exception = Server.GetLastError()TryIf ex IsNotNothing ThenWriteLog(ex)End IfServer.Transfer("~/ErrorDescriptionPage.aspx")CatchEnd TryEnd Sub

Hope this will help to identify the issue.

Thanks once again


One more thing is that I use Microsoft Entreprise Block for exception handling

Thanks


Still, I can fire the Application_Error method. I guess it's caused by come configurations. That's why I want your web.config file.

Can you post it here?

Exception not being sent

Hi there!
I'm having a little bit of trouble trying to catch exceptions thrown by the application.
I inserted the scriptmanager tag inside the head tag:
<atlas:ScriptManager ID="scriptManager" runat="server">
<Services>
<atlas:ServiceReference Path="ChatService.asmx" />
</Services>
</atlas:ScriptManager>
I've already tried to put the GenerateProxy = "true" property and still doesn't work...
when I call a webmethod, I do something like:

ClassName.WebMethod(attributes, onCallOk, onTimeout, onError);

the functions are inside a .js file.

The darkiest thing is that when the error occurs on my machine I cansee the message from the exception, but, when someone from anothermachine (acessing my machine) receives the error, the message from theexception is sent empty, even when the same occurs...

is there something that I have to do to allow remote computers to receive the exception?

thanks!!!

hi leandrokoiti,

you can have a look at Nikhil blog:

http://www.nikhilk.net/AtlasM1Refresh.aspx

they talk about that subjet

exception has been thrown by the target of invocation

Has anyone seen this before?

I would post my code, but its long and hairy, and you dont want to see it.

Basically, I have one drop down that populates a second on post-back via business objects. Whenever I change the value of the first drop down, i get a pop up box with the above error.

If I take it out of the update panel, it works fine.

Any ideas?

I just started seeing this with the same scenario. It had been working fine for the last few weeks, I'm not sure what changed to cause this to start happening. Did you get anymore info on this?

Exception has been thrown by the target of an invocation.

I have an Atlas enabled asp page working fine in Visual Web Developer 2005.

It has a Web Service with two methods one for an autocomplete and another to generate a datatable to populate a datagrid.

The second method makes calls two methods from a DataSet object.(one gets a row and the other its details.)

When I deploy to produccion the autocomplete works fine but populating the datagrid fails with:

Exception has been thrown by the target of an invocation

thrown by InternetExplorer.

I tested the Web Service calling its operations directly and it works fine.

Please help.

ps. the production machine has low space in C:\ drive.

In both cases I go against the same SQL Server 2000 database.

Since I posted the question above I was able to "deploy" to a Virtual Directory (called "LocalAtlas" situated on D:\VB Projects\VB Web Developer\Atlas Web Virtual Dir\ ) of my Local IIS and after I added the impersonation tag

<

identityimpersonate="true"userName="vvvvvvvv"password="pppppppp"/>

the page worked as expected. However, it is looking for the .asmx file in the same directory where Visual Studio looks.

But changing the KEY tag from

<

addkey="OBWebServiceRef.OBWebService"value="http://localhost:1459/AtlasWebSite1/OBWebService.asmx"/>

as created by Visual Web Dev to

<

addkey="OBWebServiceRef.OBWebService"value="http://localhost/LocalAtlas/OBWebService.asmx"/>

or anything else I can think of (in Web.config) does not work.

(I removed the fileAtlasWebSite1/OBWebService.asmxto avoid using it)

Exception has been thrown by the target of an invocation

I have a scriptmanager and updatepanel, inside the panel is a gridview it's bound to an objectdatasource, when I click the select button in the grid I get the alert with the message "Exception has been thrown by the target invocation". How would I know the source of this error, or what is causing the error. Is there a way to get the real exception that occurred not just a message?

Thanks

Disable the ajax for a moment (EnablePartialRendering="false" on the scriptmanager).
This error message is about as useful as a chocolate fireguard. Disabling the update panel is fine for development, and the few bugs that I stumble across while developing. But what about in a production situation. If I get my clients phoning up telling me the app won't work becuase an "Exception has been thrown by the target of an invocation", then I'll just explain to them how to disable AJAX so I can get a useful error message. AHH. No. I don't think so. Is there some way that you can actually pass the message text up to the popup box. Dev's like me are pretty reliant on the exception text. Especially as we often just write stuff and then it gets put into production without rigourous testing. Not ideal, but thats what happens in the real world outside of Redmond.

Was this resolved at all? I have a similar issue:

Steps to Reproduce

1) I have a DB table with a column which is varchar(1024)

2) I want this column to only contain unique strings

3) So I add a trigger to the column to check for the data entered and use RaisError if any problems

4) I setup my Datagrid/ObjectDataSource/BLL/DAL and all works fine in aspx, the page errors with the correct message.

5) I add in an AJAX Update Panel and *it* (the ASP.NET AJAX Libraries) just spits out a JSON string containing an alert message "An exception occured by the the target of an invocation". THAT is not the correct error string.

Why is it not? and how do I alter this behaviour to make it send a JSON string containing the correct Error message?

Thank


Was this resolved at all? I have a similar issue:

Steps to Reproduce

1) I have a DB table with a column which is varchar(1024)

2) I want this column to only contain unique strings

3) So I add a trigger to the column to check for the data entered and use RaisError if any problems

4) I setup my Datagrid/ObjectDataSource/BLL/DAL and all works fine in aspx, the page errors with the correct message.

5) I add in an AJAX Update Panel and *it* (the ASP.NET AJAX Libraries) just spits out a JSON string containing an alert message "An exception occured by the the target of an invocation". THAT is not the correct error string.

Why is it not? and how do I alter this behaviour to make it send a JSON string containing the correct Error message?

Thank you