Showing posts with label exception. Show all posts
Showing posts with label exception. Show all posts

Wednesday, March 28, 2012

PageMethod Exception: "An entry with the same key already exists."

I am calling a PageMethod from a javascript function. This function is called from many different controls on a page. The problem occurs about the second time the method is called. An exception is thrown saying that an entry with the same key already exists. The weird thing is that everything continues to work normally from the users perspective. I would never have noticed this behaviour if I hadn't be debugging. Its more annoying than developement breaking, but I would still like a solution to it. Except I have no idea how to proceed. Am I just using PageMethod improperly?

I'm using ASP.NET 2.0 with C# code.

My config file says this about the assembly I'm using: System.Web.Extensions, Version=1.0.61025.0

Stack trace follows...

EXCEPTION:

{"Error executing child request for /thesite/problemLog.aspx."}

STACK: atSystem.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler,TextWriter writer, Boolean preserveForm, Boolean setPreviousPage,VirtualPath path, VirtualPath filePath, String physPath, Exceptionerror, String queryStringOverride)
at System.Web.HttpServerUtility.Execute(String path, TextWriter writer, Boolean preserveForm)
at System.Web.HttpServerUtility.Transfer(String path, Boolean preserveForm)
at System.Web.HttpServerUtility.Transfer(String path)
at ASP.global_asax.Application_Error(Object sender, EventArgs e) in c:\Projects\Velocity Code\cfdrodeo\Global.asax:line 92
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Web.HttpApplication.RaiseOnError()

INNER EXCEPTION:

{"Exception of type 'System.Web.HttpUnhandledException' was thrown."}

STACK:

at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at ASP.problemlog_aspx.ProcessRequest(HttpContext context) inc:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NETFiles\cfdrodeo\0b93ea50\5991e932\App_Web_xczsyy3k.22.cs:line 0
at System.Web.HttpServerUtility.ExecuteInternal(IHttpHandlerhandler, TextWriter writer, Boolean preserveForm, BooleansetPreviousPage, VirtualPath path, VirtualPath filePath, StringphysPath, Exception error, String queryStringOverride)

INNER EXCEPTION:

{"An entry with the same key already exists."}

STACK:

at System.Collections.Specialized.ListDictionary.Add(Object key, Object value)
at System.Web.UI.ClientScriptManager.RegisterScriptBlock(ScriptKey key, String script, ListDictionary& scriptBlocks, ArrayList& scriptList, Boolean needsScriptTags, Boolean& inScriptBlock)
at System.Web.UI.ClientScriptManager.RegisterScriptBlock(ScriptKey key, String script, ClientAPIRegisterType type)
at System.Web.UI.ClientScriptManager.RegisterClientScriptInclude(Type type, String key, String url)
at System.Web.UI.ScriptRegistrationManager.RegisterClientScriptInclude(Control control, Type type, String key, String url)
at System.Web.UI.ScriptManager.RegisterClientScriptInclude(Control control, Type type, String key, String url)
at System.Web.UI.ScriptManager.RegisterClientScriptIncludeInternal(Control control, Type type, String key, String url)
at System.Web.UI.ScriptManager.RegisterScripts()
at System.Web.UI.ScriptManager.OnPagePreRenderComplete(Object sender, EventArgs e)
at System.Web.UI.Page.OnPreRenderComplete(EventArgs e)
at System.Web.UI.Page.PerformPreRenderComplete()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Thank you for your help.

Hi,

could you post the code of your page method and the JavaScript code that you use to invoke it?

PageMethods and Exceptions

Hi,
i was looking for information about how to manage Exception throwed by page methods.
I mean, is there any way in the javascript function that is called on failure of the page method to know the type of the exception throwed?
I know that the object passed as parameter to this function has the get_message() method to get the exception's message, but i can't find any other information about it.

sorry for my poor english and thanks for your answers,

bye

Well, frankly your best option is to not throw them. Either handle them inside the page method or else have some kind of catchall error handler for the page / app (or both). In terms of debugging, you can then (in the catch block) log on the server any info you might want to, and not worry about whether the javascript object will support inspection of the core problem or not.


Say you call a page method like this:
function UpdateTime()
{
PageMethods.GetCurrentDate(OnSucceeded, OnFailed);
}
function OnSucceeded(result, userContext, methodName)
{
$get('Label1').innerHTML = result;
}
function OnFailed(error, userContext, methodName)
{
$get('Label1').innerHTML = "An error occured.";
}

OnFailed will be called anytime there's an exception thrown from the web method. "error" contains several useful properties, such as error._exceptionType, error._message, and error_stackTrace.


FYI the Exception Type, StackTrace etc is not the server side objects, instead it is the client info.


gt1329a:

"error" contains several useful properties, such aserror._exceptionType, error._message, and error_stackTrace.

thank you, this is what i was looking for!

but before i mark this thread as "resolved" there's another question a want to ask you:

where did u find those information? 'cause i look for them for pretty long time but i culdn't find anything but the get_message() method.


Checkouthttp://www.asp.net/ajax/documentation/live/ClientReference/Global/JavascriptTypeExtensions/ErrorTypeExt/default.aspx andhttp://msdn2.microsoft.com/en-us/library/b8664205-d28e-4cde-bd76-69173ff72dea.aspx


thanks a lot to all of you


YaWW:

where did u find those information? 'cause i look for them for pretty long time but i culdn't find anything but the get_message() method.

I find it easier toexplore the DOM with a JavaScript debugger, than to read the docs. That's how I found the exception information. I set a breakpoint on the client side error handler and then looked at what information was returned.