Home > Enterprise >  C# fails when adding ArrayList to Existing Object
C# fails when adding ArrayList to Existing Object

Time:08-30

Working in Visual Studio 2022 on an ASP.NET web app,

I have an object named tractObject with three items. The third item is an ArrayList that will hold a list of objects named standObject.

  public class tractObject
    {
        private String tract_name = "";
        private long tract_id = 0;
        private ArrayList lstStandObject = new ArrayList(); //The list of standObject's

       public String p_lstStandObject
        {
            get
            {
                return lstStandObject;
            }
            set
            {
                lstStandObject= value;
            }
        }
            etc..
    }

I build an ArrayList of standObjects's dynamically but when I try to assign the ArrayList of standObjects to the tractObject Visual Studio throws an error with a generic error message (no details).

            //create an empty arraylist to hold the list of stand objects
            ArrayList arrList = new ArrayList();
            //call a function to get the list of stand objects - this works without error
            lstOfStandObjects = functionThatReturnsListOfStandObjects();
               
            for (int i = 0; i < lstOfStandObjects.Count; i  )
            {
               //populate the ArrayList with the stand objects - this works without error
                arrList.Add(lstOfStandObjects[i]);
            } 

            //add the ArrayList to the tractObject
            tractObject.p_lstStandObject = arrList; //<<<This is where the code fails. 

Everything works fine until I try to assign the ArrayList (arrList) to the p_lstOfStandObject. This is maddening because I have used this exact same method dozens of times in the desktop (non-web) version of this application.

CodePudding user response:

The solution had to do with the maxJsonLength setting on the JavascriptSerializer. The json string being returned to the function exceeded the default of 102,400 characters.

To fix this problem I edited the web.config file with the following inside the tags;

<system.web.extensions>
    <scripting>
        <webServices>
            <jsonSerialization maxJsonLength="2000000000"/>
        </webServices>
    </scripting>
</system.web.extensions>
  • Related