none
at System.ThrowHelper.ThrowKeyNotFoundException() at System.Collections.Generic.Dictionary`2.get_Item(TKey key) RRS feed

  • Question


  • I create method(ExtractUserMenuFromCache) in master page to bind the menu dynamically. Error is: ExtractUserMenuFromCache() The given key was not present in the dictionary. at System.ThrowHelper.ThrowKeyNotFoundException() at System.Collections.Generic.Dictionary`2.get_Item(TKey key) at System.Data.DataView.get_Item(Int32 recordIndex) at Include_Master_EMRMaster.ExtractUserMenuFromCache()

    1. Include and Master is folder and i keep Master page in this folder.

    I get the data to bind the menu from dataset through procedure. Here is the method:

    public void ExtractUserMenuFromCache() { try { string[] columnNames = new string[1]; DAL.DAL objDl = new DAL.DAL(DAL.DAL.DBType.SqlServer, sConString);

    if ((Cache["MenuDetail"] == null) || (Cache["GroupDetail"] == null) || (Cache["ModuleDetail"] == null)) { DataSet objDs = (DataSet)objDl.FillDataSet(CommandType.StoredProcedure, "uspSecurityGetUserPages"); if (objDs.Tables.Count == 3) { Cache["ModuleDetail"] = objDs.Tables[0].Copy(); Cache["GroupDetail"] = objDs.Tables[1].Copy(); Cache["MenuDetail"] = objDs.Tables[2].Copy(); } } DataTable dtMenuDetail = new DataTable(); DataTable dtGroupDetail = new DataTable(); DataTable dtModuleDetail = new DataTable(); DataTable dtDistinctModuleId = new DataTable(); DataTable dtDistinctModuleDetail = new DataTable(); DataTable dtDistinctPageId = new DataTable(); DataTable dtDistinctPageDetail = new DataTable(); dtMenuDetail = (DataTable)Cache["MenuDetail"]; dtGroupDetail = (DataTable)Cache["GroupDetail"]; dtModuleDetail = (DataTable)Cache["ModuleDetail"]; if ((dtMenuDetail.Rows.Count == 0) || (dtGroupDetail.Rows.Count == 0) || (dtModuleDetail.Rows.Count == 0)) { DataSet objDs = (DataSet)objDl.FillDataSet(CommandType.StoredProcedure, "uspSecurityGetUserPages"); if (objDs.Tables.Count == 3) { Cache["ModuleDetail"] = objDs.Tables[0].Copy(); Cache["GroupDetail"] = objDs.Tables[1].Copy(); Cache["MenuDetail"] = objDs.Tables[2].Copy(); } dtMenuDetail = (DataTable)Cache["MenuDetail"]; dtGroupDetail = (DataTable)Cache["GroupDetail"]; dtModuleDetail = (DataTable)Cache["ModuleDetail"]; } if (common.myStr(Session["IsAdminGroup"]) == "True") { columnNames = new string[1]; columnNames[0] = "ModuleId"; dtGroupDetail.DefaultView.RowFilter = ""; dtDistinctModuleId = dtGroupDetail.DefaultView.ToTable(true, columnNames); if (dtDistinctModuleId.Rows.Count > 0) { dtDistinctModuleDetail = dtModuleDetail.Clone(); foreach (DataRow dr in dtDistinctModuleId.Rows) { DataView dvModuleDetail = dtModuleDetail.DefaultView; dvModuleDetail.RowFilter = ""; dvModuleDetail.RowFilter = "ModuleId=" + common.myInt(dr["ModuleId"]); if (dvModuleDetail.Count > 0) { DataRow drSelected = dtDistinctModuleDetail.NewRow(); drSelected["ModuleId"] = common.myInt(dvModuleDetail[0]["ModuleId"]); drSelected["ModuleName"] = common.myStr(dvModuleDetail[0]["ModuleName"]); drSelected["Sequence"] = common.myInt(dvModuleDetail[0]["Sequence"]); drSelected["ModuleFlag"] = common.myStr(dvModuleDetail[0]["ModuleFlag"]); drSelected["ImageUrl"] = common.myStr(dvModuleDetail[0]["ImageUrl"]); dtDistinctModuleDetail.Rows.Add(drSelected); } } } dtDistinctPageDetail = dtMenuDetail.Copy(); if (dtDistinctModuleDetail.Rows.Count > 0) { dtDistinctModuleDetail.DefaultView.Sort = ""; dtDistinctModuleDetail.DefaultView.Sort = "Sequence Asc"; ViewState["mainMenu"] = dtDistinctModuleDetail; } if (dtMenuDetail.Rows.Count > 0) { dtMenuDetail.DefaultView.RowFilter = "IsPopupPage=False"; dtMenuDetail.DefaultView.Sort = ""; dtMenuDetail.DefaultView.Sort = "Hierarchy,Sequence Asc"; ViewState["MenuData"] = dtMenuDetail.DefaultView.ToTable(); ViewState["PharmacyIntimationRights"] = "Y"; ViewState["BillingIntimationRights"] = "Y"; ViewState["ICIntimationRights"] = "Y"; ViewState["BedTransferRequest"] = "Y"; } } else { dtGroupDetail.DefaultView.RowFilter = ""; dtGroupDetail.DefaultView.RowFilter = "GroupId=" + common.myInt(Session["GroupId"]); Session["PrintAuthentication"] = dtGroupDetail.DefaultView.ToTable(); if (dtGroupDetail.Rows.Count > 0) { columnNames = new string[1]; columnNames[0] = "ModuleId"; dtDistinctModuleId.DefaultView.RowFilter = ""; dtDistinctModuleId = dtGroupDetail.DefaultView.ToTable(true, columnNames); if (dtDistinctModuleId.Rows.Count > 0) { dtDistinctModuleDetail = dtModuleDetail.Clone(); foreach (DataRow dr in dtDistinctModuleId.Rows) { DataView dvModuleDetail = dtModuleDetail.DefaultView; dtModuleDetail.DefaultView.RowFilter = ""; dtModuleDetail.DefaultView.RowFilter = "ModuleId=" + common.myInt(dr["ModuleId"]); if (dtModuleDetail.Rows.Count > 0) { DataRow drSelected = dtDistinctModuleDetail.NewRow(); drSelected["ModuleId"] = common.myInt(dvModuleDetail[0]["ModuleId"]); drSelected["ModuleName"] = common.myStr(dvModuleDetail[0]["ModuleName"]); drSelected["Sequence"] = common.myInt(dvModuleDetail[0]["Sequence"]); drSelected["ModuleFlag"] = common.myStr(dvModuleDetail[0]["ModuleFlag"]); drSelected["ImageUrl"] = common.myStr(dvModuleDetail[0]["ImageUrl"]); dtDistinctModuleDetail.Rows.Add(drSelected); } } dtGroupDetail.DefaultView.RowFilter = ""; dtGroupDetail.DefaultView.RowFilter = "GroupId=" + common.myInt(Session["GroupId"]); if (dtGroupDetail.Rows.Count > 0) { dtDistinctPageDetail = dtMenuDetail.Clone(); foreach (DataRowView drv in dtGroupDetail.DefaultView) { DataView dvPageDetails = dtMenuDetail.DefaultView; dvPageDetails.RowFilter = ""; dvPageDetails.RowFilter = "PageId=" + common.myInt(drv["PageId"]); if (dvPageDetails.Count > 0) { DataRow drSelected = dtDistinctPageDetail.NewRow(); drSelected["ModuleId"] = common.myInt(dvPageDetails[0]["ModuleId"]); drSelected["PageId"] = common.myInt(dvPageDetails[0]["PageId"]); drSelected["PageName"] = common.myStr(dvPageDetails[0]["PageName"]); drSelected["ParentId"] = common.myInt(dvPageDetails[0]["ParentId"]); drSelected["Hierarchy"] = common.myStr(dvPageDetails[0]["Hierarchy"]); drSelected["Sequence"] = common.myInt(dvPageDetails[0]["Sequence"]); drSelected["PageUrl"] = common.myStr(dvPageDetails[0]["PageUrl"]); drSelected["IsPopupPage"] = common.myStr(dvPageDetails[0]["IsPopupPage"]); dtDistinctPageDetail.Rows.Add(drSelected); } } } } if (dtDistinctModuleDetail.Rows.Count > 0) { dtDistinctModuleDetail.DefaultView.Sort = "Sequence Asc"; ViewState["mainMenu"] = dtDistinctModuleDetail; } if (dtDistinctPageDetail.Rows.Count > 0) { dtDistinctPageDetail.DefaultView.RowFilter = "IsPopupPage=false"; dtDistinctPageDetail.DefaultView.Sort = ""; dtDistinctPageDetail.DefaultView.Sort = "Hierarchy,Sequence Asc"; ViewState["MenuData"] = dtDistinctPageDetail.DefaultView.ToTable(); dtDistinctPageDetail.DefaultView.RowFilter = string.Concat("PageUrl LIKE '%PatientIntimationStatus.aspx?PT=PHR%'"); if (dtDistinctPageDetail.DefaultView.Count > 0) { ViewState["PharmacyIntimationRights"] = "Y"; } else { ViewState["PharmacyIntimationRights"] = "N"; } dtDistinctPageDetail.DefaultView.RowFilter = string.Concat("PageUrl LIKE '%PatientIntimationStatus.aspx?PT=BILL%'"); if (dtDistinctPageDetail.DefaultView.Count > 0) { ViewState["BillingIntimationRights"] = "Y"; } else { ViewState["BillingIntimationRights"] = "N"; } dtDistinctPageDetail.DefaultView.RowFilter = string.Concat("PageUrl LIKE '%PatientIntimationStatus.aspx?PT=IC%'"); if (dtDistinctPageDetail.DefaultView.Count > 0) { ViewState["ICIntimationRights"] = "Y"; } else { ViewState["ICIntimationRights"] = "N"; } dtDistinctPageDetail.DefaultView.RowFilter = string.Concat("PageUrl LIKE '%/ATD/BedTransferRequest.aspx%'"); if (dtDistinctPageDetail.DefaultView.Count > 0) { ViewState["BedTransferRequest"] = "Y"; } else { ViewState["BedTransferRequest"] = "N"; } dtDistinctPageDetail.DefaultView.RowFilter = ""; } } } } catch (Exception Ex) { string lineNumber = Ex.StackTrace.Substring(Ex.StackTrace.Length - 7, 7); objException.HandleExceptionWithMethod(Ex, "ExtractUserMenuFromCache" + lineNumber); } }

    Because of this error my menu are blank frequently and logout the application. I request to give me solution. I am helpless this issue. I don't know what is the issue. I don't see problem in web.config configuration. I would appreciate if anyone give me the solution. Thanks


    Monday, June 9, 2014 10:58 AM

All replies

  • Hello,

    Are you using above code in sharepoint? Your question seems more related to .NET. Please confirm


    Hemendra:Yesterday is just a memory,Tomorrow we may never see
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

    Friday, June 13, 2014 9:01 AM
    Moderator