[CLOSED] Nullable parameters on DirectMethod

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] Nullable parameters on DirectMethod

    Afternoon all,

    I've recently updated our Ext.NET dlls to version 1.5.1.0 and seem now to be hitting an exception when calling DirectMethods with nullable parameters.
    e.g.
        [DirectMethod]
        public void DoSomething(int? lUserID, int? lTeamID, int? lDepartmentID)
        {
            ...
        }
    Now gives me an exception of this ilk:

    Newtonsoft.Json.JsonReaderException: Unexpected end when reading integer. Line 0, position 0. at Newtonsoft.Json.JsonTextReader.ReadAsInt32() at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter, Boolean inArray) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) at Ext.Net.DirectMethod.Invoke(Object target, HttpContext context, ParameterCollection args) at Ext.Net.ResourceManager.RaisePostBackEvent(String eventArgument)
    I thought originally it was because a couple of those params were being passed at an empty string rather than a JS null. So I reworked the calling function to ensure that the JSON was valid, e.g.

    submitDirectEventConfig    {"config":{"extraParams":{"lUserID":"1427","lTeamID":null,"lDepartmentID":null}}}
    But this still gives the exception.

    I did find an old post on here suggesting that Ext.NET prior to version 2 doesn't support nullable parameters, but this seems a little odd as prior to updating things were working happily.

    Is this possibly due to the version of JSON.NET used? or is there a sensible workaround to avoid me needing to re-write all the server side methods to not use nullables?

    Many thanks,

    Doug
    Last edited by Daniil; Sep 05, 2012 at 1:54 PM. Reason: Please use [CODE] tags, [CLOSED]
  2. #2
    Hi,

    Quote Originally Posted by DougMcDonald View Post
    I've recently updated our Ext.NET dlls to version 1.5.1.0 and seem now to be hitting an exception when calling DirectMethods with nullable parameters.
    I am unable to reproduce this regression in the functionality. The following example works the same way (in particular, throws the same exceptions) with v1.3 and the last sources from SVN (should be the same as v1.5 is).

    Example
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        [DirectMethod]
        public void Test(int? number)
        {
            X.Msg.Alert("DirectMethod", number != null ? number.ToString() : "null").Show();
        }
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.NET Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
    
            <ext:Button runat="server" Text="DirectMethod with a number argument">
                <Listeners>
                    <Click Handler="Ext.net.DirectMethods.Test(1);" />
                </Listeners>
            </ext:Button>
    
            <ext:Button runat="server" Text="DirectMethod without any argument">
                <Listeners>
                    <Click Handler="Ext.net.DirectMethods.Test();" />
                </Listeners>
            </ext:Button>
    
            <ext:Button runat="server" Text="DirectMethod with a null argument">
                <Listeners>
                    <Click Handler="Ext.net.DirectMethods.Test(null);" />
                </Listeners>
            </ext:Button>
        </form>
    </body>
    </html>
    Anyway, I will discuss with my colleagues a possibility to get it working.
  3. #3
    Hi Daniil,

    Thanks for taking a look at this one, if it's any help, our original DLL's were as follows:

    Ext.Net.dll - 1.2.0.21133
    Ext.Net.Factory.dll - 1.0.0.0
    Ext.Net.Utilities - 1.1.0.21129
    Ext.Net.UX - 1.0.0.14097
    Newtonsoft.Json.dll - 3.5.0.0

    I can pop them over in a zip or something if it would help,

    Cheers,

    Doug
  4. #4
    Confirm, "DirectMethod with a null argument" works with v1.2.

    But are you saying "DirectMethod without any argument" worked well before update? Did I understand correctly?
  5. #5
    Hi Daniil,

    To clarify, in our existing code (that which hasn't been changed in the last few months) we have a DirectMethod defined with nullable params, as below:

        [DirectMethod(ShowMask = true, Target = MaskTarget.Page, Msg = "Loading...", SuccessFn = "userloadingUpdateChartSuccess")]
        public void PopulateForm(byte lNumberOfWeeks, DateTime datStartWeek, int? lUserID, int? lTeamID, int? lDepartmentID, bool bpAverage, bool bReload, bool bAddColumns)
        {
          //the method
        }
    This was called from client side code, using the following method:

    function userloadingUpdateChart(oSender, datNewDate) {
        var lpTeamID = hidTeamID.getValue();
        var lpUserID = hidUserID.getValue();
        var lpDepartmentID = hidDepartmentID.getValue();
        var lpCurrentWeekSpan = hidCurrentNumberOfWeeks.getValue();
        var bpAverage = hidAverage.getValue() === "1";
        
        lpTeamID = userLoadingJsonNullCheck(lpTeamID);
        lpUserID = userLoadingJsonNullCheck(lpUserID);
        lpDepartmentID = userLoadingJsonNullCheck(lpDepartmentID);
    
        strLoading.clearData();
    
        Ext.net.DirectMethods.PopulateForm(lpCurrentWeekSpan, datNewDate, lpUserID, lpTeamID, lpDepartmentID, bpAverage, true, false);
    }
    As you can see, previously the parameters were provided by the result of .getValue() on some hidden fields. If the hidden fields weren't populated would return "".
    As a quick fix I thought I'd do a quick checking function which simply checks for "" and returns nulls to ensure that the JSON getting passed to the PopulateForm() method was actually getting nulls not empty strings.

    function userLoadingJsonNullCheck(value) {
    
        if (value === "") {
            return null;
        } else {
            return value;
        }
    }
    Unfortunately, neither leaving the getValue() calls as they were, or providing nulls in place of "" seems to allow me to call the DirectMethod with int? parameters.
  6. #6
    Thanks for clarification.

    Yes, it happened due to updating Json.NET.

    It has been fixed in SVN branches/1, revision #4322.

    Thank you for the report!
  7. #7
    Ah ok, the SVN branches of Ext.NET or JSON.Net?
  8. #8
  9. #9
    Hi Daniil,

    Thanks for the info, I'm afraid our network doesn't allow an SVN connection directly. I'll have to see if I can get a copy offsite and sent it to myself once built.

    I don't suppose you guys have a build copy of the latest branch I could nab in the meantime do you? Don't worry if it's a pain to provide.

    Cheers,

    Doug
  10. #10
    I can send you the last dlls. Do you need it to be be built in Release or Debug mode?

    Also please provide your email.
Page 1 of 2 12 LastLast

Similar Threads

  1. Nullable Parameters
    By Zdenek in forum 1.x Help
    Replies: 1
    Last Post: Mar 16, 2012, 6:54 PM
  2. nullable TextField with Vtype of email
    By javadzarrin in forum 1.x Help
    Replies: 1
    Last Post: Sep 06, 2010, 7:40 PM
  3. [CLOSED] Why ThreeStateBool instead Nullable<bool>?
    By pil0t in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Aug 31, 2010, 2:38 PM
  4. [CLOSED] Nullable number field
    By Stefanaccio in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jun 02, 2010, 5:06 PM
  5. [CLOSED] Nullable (three state) checkbox
    By pil0t in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: May 25, 2010, 10:41 AM

Tags for this Thread

Posting Permissions