NullReferenceException when using ServerMapping

  1. #1

    NullReferenceException when using ServerMapping

    Hi,

    I'm using ServerMapping on RecordFields for complex objects. I specified a property that doesn't exist. This threw a NullReferenceException when the data was being bound.
    It took me a while to check why there is the exception. I think it should throw a more detailled exception that tells me that the property does not exist.

    public abstract partial class StoreDataBound
    Name:  1.png
Views: 361
Size:  14.1 KB
  2. #2
    Hi,

    Please clarify how we can reproduce it?

    I set non-existing property for ServerMapping but the issue doesn't appear.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        class Test
        {
            public string Test1 { get; set; }
            public string Test2 { get; set; }
        }
    
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                Store store = this.GridPanel1.GetStore();
                store.DataSource = new object[] 
                { 
                    new Test 
                    { 
                        Test1 = "test11", 
                        Test2 = "test12"
                    },
                };
                store.DataBind();
            }
        }
    </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:GridPanel ID="GridPanel1" runat="server" AutoHeight="true">
            <Store>
                <ext:Store runat="server">
                    <Reader>
                        <ext:JsonReader>
                            <Fields>
                                <ext:RecordField Name="test11" ServerMapping="Test1" />
                                <ext:RecordField Name="test2" ServerMapping="notExists" />
                            </Fields>
                        </ext:JsonReader>
                    </Reader>
                </ext:Store>
            </Store>
            <ColumnModel runat="server">
                <Columns>
                    <ext:Column Header="Test1" DataIndex="test1" />
                    <ext:Column Header="Test2" DataIndex="test2" />
                </Columns>
            </ColumnModel>
        </ext:GridPanel>
        </form>
    </body>
    </html>
  3. #3
    Try specifying a nested property:

    class Test
    {
        public Test2 Test1 { get; set; }
        public string Test2 { get; set; }
    }
    
    class Test2
    {
        public string NestedTest1 { get; set; }
    }
    <ext:RecordField Name="test2" ServerMapping="Test1.NestedTest1" /> // works
    <ext:RecordField Name="test2" ServerMapping="Test1.notExists" /> // Exception
  4. #4
    Thank you, now I reproduced.

    I will discuss this issue with Dev team.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        class Test
        {
            public Test2 Test1 { get; set; }
            public string Test2 { get; set; }
        }
    
        class Test2
        {
            public string NestedTest1 { get; set; }
        }
    
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                Store store = this.GridPanel1.GetStore();
                store.DataSource = new object[] 
                { 
                    new Test 
                    { 
                        Test1 = new Test2() 
                        {
                          NestedTest1 = "test11" 
                        }, 
                        Test2 = "test12"
                    },
                };
                store.DataBind();
            }
        }
    </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:GridPanel ID="GridPanel1" runat="server" AutoHeight="true">
            <Store>
                <ext:Store runat="server">
                    <Reader>
                        <ext:JsonReader>
                            <Fields>
                                <ext:RecordField Name="test1" ServerMapping="Test1.NestedTest1" />
                                <ext:RecordField Name="test2" ServerMapping="Test1.notExists" />
                            </Fields>
                        </ext:JsonReader>
                    </Reader>
                </ext:Store>
            </Store>
            <ColumnModel runat="server">
                <Columns>
                    <ext:Column Header="Test1" DataIndex="test1" />
                    <ext:Column Header="Test2" DataIndex="test2" />
                </Columns>
            </ColumnModel>
        </ext:GridPanel>
        </form>
    </body>
    </html>
  5. #5
    I love it to enhance things :)
  6. #6
    Hi @nextSTEP,

    The related feature ticket:
    https://extnet.lighthouseapp.com/pro...res/tickets/91

    This has been implemented, revision #3570.

    It will be also available in RC2.

    Thanks for pointing it out.

Similar Threads

  1. DirectMethod NullReferenceException
    By bayoglu in forum 1.x Help
    Replies: 2
    Last Post: Apr 04, 2012, 4:26 PM
  2. [CLOSED] System.NullReferenceException
    By syllabusarq in forum 1.x Legacy Premium Help
    Replies: 8
    Last Post: Mar 07, 2011, 9:15 PM
  3. DirectMethod - NullReferenceException
    By grombox in forum 1.x Help
    Replies: 2
    Last Post: Dec 07, 2010, 5:34 AM
  4. Replies: 1
    Last Post: Sep 04, 2009, 9:32 AM
  5. Replies: 1
    Last Post: Dec 12, 2008, 1:10 PM

Posting Permissions