[CLOSED] Nullable parameters on DirectMethod

Hybrid View

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

    [CLOSED] Nullable parameters on DirectMethod

    Afternoon all,

    I've recently updated our Ext.NET dlls to version and seem now to be hitting an exception when calling DirectMethods with nullable parameters.
        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,

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

    Quote Originally Posted by DougMcDonald View Post
    I've recently updated our Ext.NET dlls to version 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).

    <%@ Page Language="C#" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <script runat="server">
        public void Test(int? number)
            X.Msg.Alert("DirectMethod", number != null ? number.ToString() : "null").Show();
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.NET Example</title>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:Button runat="server" Text="DirectMethod with a number argument">
                    <Click Handler="Ext.net.DirectMethods.Test(1);" />
            <ext:Button runat="server" Text="DirectMethod without any argument">
                    <Click Handler="Ext.net.DirectMethods.Test();" />
            <ext:Button runat="server" Text="DirectMethod with a null argument">
                    <Click Handler="Ext.net.DirectMethods.Test(null);" />
    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 -
    Ext.Net.Factory.dll -
    Ext.Net.Utilities -
    Ext.Net.UX -
    Newtonsoft.Json.dll -

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


  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);
        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!

Similar Threads

  1. Nullable Parameters
    By Zdenek in forum 1.x Help
    Replies: 1
    Last Post: Mar 16, 2012, 7:54 PM
  2. nullable TextField with Vtype of email
    By javadzarrin in forum 1.x Help
    Replies: 1
    Last Post: Sep 06, 2010, 8: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, 3:38 PM
  4. [CLOSED] Nullable number field
    By Stefanaccio in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jun 02, 2010, 6:06 PM
  5. [CLOSED] Nullable (three state) checkbox
    By pil0t in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: May 25, 2010, 11:41 AM

Tags for this Thread

Posting Permissions