[CLOSED] DirectMethod difference between static and non-static and request for more exception information

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    [CLOSED] DirectMethod difference between static and non-static and request for more exception information

    Hi,

    Consider this contrived example:

    <%@ Page Language="C#" %>
    <%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
        [DirectMethod]
        public static void TestStaticDirectMethod(object sender, EventArgs e)
        {
            ExtNet.MessageBox.Show(new MessageBoxConfig { Message = "1. Static Direct Method's message" });
        }
    
        [DirectMethod]
        public void TestDirectMethod(object sender, EventArgs e)
        {
            ExtNet.MessageBox.Show(new MessageBoxConfig { Message = "2. Direct Method's message"});
        }
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Direct Method exception detail test</title>
    </head>
    <body>
        <form id="HtmlForm" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" DirectMethodNamespace="CompanyX" />
        </form>
        <script type="text/javascript">
            Ext.onReady(function() {
                CompanyX.TestStaticDirectMethod(0);
                CompanyX.TestDirectMethod(0);
            });
        </script>
    </body>
    </html>
    This is what I see:

    1. The static method runs and we see the message box
    2. The non-static method shows an exception in the Ext window. The message is this:

     System.ArgumentException: The parameter 'e' is null
     at  Ext.Net.DirectMethod.Invoke(Object target, HttpContext context,  ParameterCollection args)
     at  Ext.Net.ResourceManager.RaisePostBackEvent(String eventArgument)
    Requested enhancement #1: Make invocation exception behaviour between static and non-static DirectMethods more consistent

    To be fair, I can understand if this cannot be done, or cannot be done easily. I am guessing that why the static method works and the instance method fails is as follows:

    • Although the DirectMethod signature has object sender and EventArgs e the JavaScript is sending just an integer only.
    • But the integer just becomes a string during the ajax request, and on the server side is successfully deserialized to the first parameter because it is of type Object.
    • I do notice that e is null in the static method.
    • In the case of the instance method, without looking at your source code, I assume it is very similar for the instance method, but that there is probably a small layer in between so invoking or calling that delegate with null would likely cause problems, so I can understand there might be a reason for the seemingly inconsistent behaviour between the static and non-static direct methods).

    Requested enhancement #2: report the name of the method being invoked.

    The non-static version can certainly be fixed by us developers simply ensuring the signatures match up (e.g. replacing Object sender, EventArgs e with an integer parameter). But regardless, I think there will still be times this exception occurs and when it does, reporting the method being invoked would save a lot of time.

    For example, a colleague was doing this in a much larger code base (though he is very new to Ext.Js) and spent over 8 hours trying to figure out why he was getting this exception. Luckily when he asked me I eventually saw the issue was the signature mis-match. The real code had a LOT more going on, so narrowing down onto this method took a while (because he had many DirectMethods with "e" as the EventArgs parameter name)

    So, I hope it is possible to also include the name of the method being invoked (e.g. maybe wrap the inner ArgumentNullException with your own that describes the direct method?)

    Thanks!
    Last edited by Daniil; May 16, 2011 at 1:26 PM. Reason: [CLOSED]

Similar Threads

  1. [CLOSED] Calling Static DirectMethod defined in an UserControl
    By ISI in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Aug 05, 2011, 9:16 AM
  2. [CLOSED] Difference between DirectMethod , DirectEvent, Static DirectMethod
    By syllabusarq in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Mar 01, 2011, 11:37 AM
  3. [CLOSED] DirectEvent or static DirectMethod?
    By macap in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Nov 23, 2010, 12:31 PM
  4. [CLOSED] Static DirectMethod
    By amitpareek in forum 1.x Legacy Premium Help
    Replies: 21
    Last Post: Jun 03, 2010, 12:42 AM
  5. Handle exception and static method
    By Yannis in forum 1.x Help
    Replies: 4
    Last Post: Dec 18, 2009, 11:45 AM

Posting Permissions