[CLOSED] DirectMethod difference between static and non-static and request for more exception information
Hi,
Consider this contrived example:
Code:
<%@ 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:
- The static method runs and we see the message box
- The non-static method shows an exception in the Ext window. The message is this:
Code:
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!