A first chance exception of type 'System.OutOfMemoryException' occurred in System.Windows.ni.dll

jacobkurien

New member
Jun 3, 2013
1
0
0
Visit site
I am writing a windows phone 8 application. I am seeing the following error: A first chance exception of type 'System.OutOfMemoryException' occurred in System.Windows.ni.dll I have zoned the code that causes this error, but i am not able to fix it. Feel free to help me out here

Code:
public void getTheWholeChapter(string startbooknum, string startchapter)
        {
            System.Uri uri = new Uri("http://api.seek-first.com/v1/BibleSearch.php?type=lookup&appid=seekfirst&startbooknum=" + startbooknum + "&startchapter=" + startchapter + "&startverse=1&endbooknum=" + startbooknum + "&endchapter=" + startchapter + "&endverse=5000000&version=KJV");
            WebClient client = new WebClient();
            OpenReadCompletedEventHandler orceh = new OpenReadCompletedEventHandler(GetTheData);
            client.OpenReadCompleted += orceh;
            client.OpenReadAsync(uri);
        }

        private void GetTheData(object sender, OpenReadCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                StreamReader reader = new StreamReader(e.Result);
                string stringXML = reader.ReadToEnd().ToString();

                ListBox tb = new ListBox();
                //tb.IsGroupingEnabled = true;
                //tb.HideEmptyGroups = true;
                //tb.LayoutMode = LongListSelectorLayoutMode.List;
                tb.FontSize = 25;
                List<TextBlock> listOfVerses = new List<TextBlock>();

                

                //get the deatails from the 
                if (stringXML != "" && stringXML != null)
                {
                    XDocument root = XDocument.Parse("<Document>" + stringXML.Replace("></a>", "/></a>") + "</Document>");
                    var ResultsX = from Results in root.Descendants("Result")
                                   select Results;
                    foreach (var Result in ResultsX)
                    {
                        listOfVerses.Add(new TextBlock()
                        {
                            Text = Result.Element("Chapter").Value + ":" + Result.Element("Verse").Value + "  " + Result.Element("Text").Value,
                            TextWrapping = TextWrapping.Wrap,

                        });
                    }
                }
                tb.ItemsSource = listOfVerses;
                ((PivotItem)this.chaptersPivot.Items[chaptersPivot.SelectedIndex]).Content = tb;
                
            }
            else
            {
                //handle this
            }
            //throw new NotImplementedException();
        }
 

crash1989

New member
Oct 30, 2012
1,491
0
0
Visit site
Could you please move this thread to the developers corner forums.

Can you step into each line while debugging and figure exactly where the error is. I have a hunch it might be readtoend method which is causing the issue.

Just another suggestion below, you could ignore it.
Use databinding for controls (google it) , it will greatly reduce your backend code complexity
 

Members online

Forum statistics

Threads
323,131
Messages
2,243,310
Members
428,030
Latest member
quicktravo