i am using following code to generate ordered list. this code create exception on line number 73, 106, 108 when this page is refreshed during load testing. menu gets created in development and testing environment. it crashes on production side or during load testing **
try
{
dtDepartments = DB.GetDataSet("[dbo].[Departments]", AppLogic.CachingOn).Tables[0];
dtCategories = DB.GetDataSet("[dbo].[Categories]", AppLogic.CachingOn).Tables[0];
foreach (DataRow drDept in dtDepartments.Rows)
{
dtCategories.DefaultView.RowFilter = "[SEName] Like '" + drDept["SEName"].ToString() + "-%' And [ParentCategoryId] = 0";
CategoryView = null;
CategoryView = dtCategories.DefaultView;
foreach (DataRowView CategoryRowView in CategoryView)
{
DataRow CategoryRow = CategoryRowView.Row; \\line number 73
dtCategories.DefaultView.RowFilter = "[SEName] Like '" + drDept["SEName"].ToString() + "-%' And [ParentCategoryId] = " + CategoryRow["CategoryID"].ToString();
CategoryViewTwoCount = dtCategories.DefaultView.Count;
CategoryViewTwo = null;
if (CategoryViewTwoCount > 0)
{
CategoryViewTwo = dtCategories.DefaultView;
}
else
{
}
if (CategoryViewTwoCount > 0)
{
foreach (DataRowView CategoryRowViewTwo in CategoryViewTwo) \\line number 106
{
DataRow CategoryRowTwo = CategoryRowViewTwo.Row; \\line number 108
}
}
}
}
TreeMenu = HTMLContents.ToString();
if (CategoryViewTwo != null)
{
CategoryViewTwo = null;
}
if (CategoryView != null)
{
CategoryView = null;
}
HTMLContents = null;
dtCategories.Dispose();
dtDepartments.Dispose();
dtCategories = null;
dtDepartments = null;
}
catch (Exception ex)
{
//Log for staging
//AppLogic.WriteAppLogs(string.Format("Exception:\n{0}\nMessage:\n{1}Inner Exception:\n{2}\nStack Trace:{3}", ex.ToString(), ex.Message.ToString(), ex.InnerException.ToString(), ex.StackTrace.ToString()));
AppLogic.WriteAppLogs("Source " + ex.Source + ex.Message + ex.StackTrace);
//Log for production
//DB.ExecuteSQL(String.Format("INSERT INTO ErrorLog (source, errormsg) VALUES ({0}, {1})", DB.SQuote(CommonLogic.GetThisPageName(true)), DB.SQuote(ex.ToString())));
}
return TreeMenu;
Here is the Exception Log
Source App_Web_treeviewnew.aspx.cdcab7d2.de1ldkd2 Object reference not set to an instance of an object. at treeview.DisplayTreeMenu() in treeviewNew.aspx.cs:line 108 6/14/2013 5:25:19 PM
Source mscorlib The given key was not present in the dictionary. at System.Collections.Generic.Dictionary`2.get_Item(TKey key) at System.Data.DataView.CopyTo(DataRowView[] array, Int32 index) at System.Data.DataView.GetEnumerator() at treeview.DisplayTreeMenu() in treeviewNew.aspx.cs:line 106 6/14/2013 5:26:03 PM
Source mscorlib The given key was not present in the dictionary. at System.Collections.Generic.Dictionary`2.get_Item(TKey key) at System.Data.DataView.CopyTo(DataRowView[] array, Int32 index) at System.Data.DataView.GetEnumerator() at treeview.DisplayTreeMenu() in treeviewNew.aspx.cs:line 106 6/14/2013 5:26:38 PM
Source mscorlib The given key was not present in the dictionary. at System.Collections.Generic.Dictionary`2.get_Item(TKey key) at System.Data.DataView.CopyTo(DataRowView[] array, Int32 index) at System.Data.DataView.GetEnumerator() at treeview.DisplayTreeMenu() in treeviewNew.aspx.cs:line 106 6/14/2013 5:26:52 PM
Source mscorlib The given key was not present in the dictionary. at System.Collections.Generic.Dictionary`2.get_Item(TKey key) at System.Data.DataView.CopyTo(DataRowView[] array, Int32 index) at System.Data.DataView.GetEnumerator() at treeview.DisplayTreeMenu() in treeviewNew.aspx.cs:line 106 6/14/2013 5:27:04 PM
Source App_Web_treeviewnew.aspx.cdcab7d2.de1ldkd2 Object reference not set to an instance of an object. at treeview.DisplayTreeMenu() in treeviewNew.aspx.cs:line 108 6/14/2013 5:28:01 PM
Source mscorlib The given key was not present in the dictionary. at System.Collections.Generic.Dictionary`2.get_Item(TKey key) at System.Data.DataView.CopyTo(DataRowView[] array, Int32 index) at System.Data.DataView.GetEnumerator() at treeview.DisplayTreeMenu() in treeviewNew.aspx.cs:line 106 6/14/2013 5:29:45 PM
Source App_Web_treeviewnew.aspx.cdcab7d2.de1ldkd2 Object reference not set to an instance of an object. at treeview.DisplayTreeMenu() in treeviewNew.aspx.cs:line 108 6/14/2013 5:31:09 PM
Source App_Web_treeviewnew.aspx.cdcab7d2.de1ldkd2 Object reference not set to an instance of an object. at treeview.DisplayTreeMenu() in treeviewNew.aspx.cs:line 73 6/14/2013 5:32:14 PM
Source mscorlib The given key was not present in the dictionary. at System.Collections.Generic.Dictionary`2.get_Item(TKey key) at System.Data.DataView.CopyTo(DataRowView[] array, Int32 index) at System.Data.DataView.GetEnumerator() at treeview.DisplayTreeMenu() in treeviewNew.aspx.cs:line 106 6/14/2013 5:32:27 PM