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

Page 1 of 2 12 LastLast
  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 2:26 PM. Reason: [CLOSED]
  2. #2
    Hi @anup,

    For now, please investigate this thread:
    http://forums.ext.net/showthread.php?12613

    It should shed some light on your questions.
  3. #3
    Hi,

    Thanks for the reporting.
    Static direct method uses query string to pass parameters, we use Ext.urlEncode to convert object to string and urlEncode converts undefined params to empty string.

    Now we remove undefined params from query string
    Name of direct method is added to exception string
    Please update from SVN
    Vladimir Shcheglov
    Sr. Developer
  4. #4
    Vladimir: many thanks for quick turn around. I will get source shortly and confirm.

    By the way, is there a way to allow static Direct Methods to take parameters as POST instead of via Query String? Just in case there are times when very large amounts of data need to be sent?
  5. #5
    Hi,

    Just set Method=HttpMethod.POST for direct method
    [DirectMethod(Method = HttpMethod.POST)]
    Vladimir Shcheglov
    Sr. Developer
  6. #6
    Hi,

    Thanks for the tip on the Method.

    I just tried the latest code. It kinda works in that they both are consistent in the exception raising now, but am seeing the effects described here and in the attached screenshots:

    Using the same code I originally posted, most of the times I get the first screenshot where there are 2 Ext Windows (on top of each other so you have to move them), but they report the same exception (i.e. the same method is reported twice, even though Firebug shows each method has failed). In otherwords, the TestDirectMethod is reported as the method name for both failures.

    After a few refreshes, I can get the second screenshot, which is the same exception but this time reported on the first method, the static one.
    Attached Thumbnails 1 - Non-Static Direct Method Exception.png   2 - Static Direct Method Exception.png  
  7. #7
    Hi,

    Unfortunately, I cannot reproduce it.
    I tested your sample and have two different messages in the windows
    Vladimir Shcheglov
    Sr. Developer
  8. #8
    Quote Originally Posted by Vladimir View Post
    Hi,

    Unfortunately, I cannot reproduce it.
    I tested your sample and have two different messages in the windows
    Hm... that's really odd...

    Just to be sure I copied my own sample from this post and definitely get the duplicate messages.

    I then added a couple of buttons and manually clicked those one by one, and in that case it works fine - I see two different messages, as expected:

    <ext:Button ID="Button1" runat="server" Text="Call Static">
        <Listeners>
            <Click Handler="CompanyX.TestStaticDirectMethod(0);" />
        </Listeners>
    </ext:Button>
    
    <ext:Button ID="Button2" runat="server" Text="Call non-Static">
        <Listeners>
            <Click Handler="CompanyX.TestDirectMethod(0);" />
        </Listeners>
    </ext:Button>
    I'll try to dig further...
  9. #9
    No joy. I am still getting both Ext windows showing the same message for the same method only when two notifications are sent on the page load (the button clicks are fine).

    I have recently switched to Windows Server 2008 R2 (IIS 7.5) though my test project remains in ASP.NET 3.5 for the moment. Is that the set up you have too?
  10. #10
    Sorry for yet another post, but just as I submitted my last one, I tried again and noticed something odd - if I refreshed that page again, it worked. But I refreshed again and it didn't. Basically approximately 95% of the time, when I force reload/refresh the page (ctrl F5 in Firefox), I get the duplicate message. Very occasionally I see the duplicate message switch to the other message (as per my earlier second screenshot), and even more rarely (just once so far) I have seen it actually work right!

    Could you try refreshing the page multiple times, perhaps to see if you see similar behaviour?
Page 1 of 2 12 LastLast

Similar Threads

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

Posting Permissions