Click here to Skip to main content
15,917,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a web service and am refering the webservice to asp.net code.The asp.et page in which am retrieving the image from server and loading it to iframe but am getting the error but i could not locate the error please suggest. what to do to over come the error.

System.Collections.Generic.KeyNotFoundException: 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.GetRowView(Int32 record)
at System.Data.DataView.CopyTo(DataRowView[] array, Int32 index)
at System.Data.DataView.GetEnumerator()
at System.Data.DataView.ToTable(String tableName, Boolean distinct, String[] columnNames)
at System.Data.DataView.ToTable()
at Tcss.GetInfoFromLocalAgent.GetDbNameByDesc(String Desc, Int32 LanguageType)
at Tcss.GetInfoFromLocalAgent.GetWidthAndHeightByRowID_BL(Int32 Tpn, Int32 RowID, Int32 LanguageType)
at ShowDoc.Page_Load(Object sender, EventArgs e)
Posted
Comments
BillWoodruff 19-Nov-14 7:14am    
Without seeing your code, we can only take a wild guess at what's going on. However, the mention of an apparently generic dictionary immediately draws my attention: what is that Dictionary's relation to a DataTable row ?
karthikeyan9966 19-Nov-14 10:54am    
can u guess y these occurs
Praveen Kumar Upadhyay 28-Nov-14 1:51am    
Please post your code and explain the problem a little more.

1 solution

Hi Karthikeyan,


See below example for how this type of exception occurs.

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MyAnswers
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {

            Dictionary<int, string> objDic = new Dictionary<int, string>();

            objDic.Add(1, "A");
            objDic.Add(2, "B");

            Console.Write(objDic[3]);//Trying to read the value of a key which does not exist in the dictionary.So exception occurs.
            Console.Read();
            }

            catch(Exception ex)
            {

                Console.Write(ex);
                Console.Read();

            }

        }
    }
}



If we had tried to get the values of the keys 1,2 from the dictionary it would have worked fine.

I hope,now you have understood how this occurs.Debug it and check that from where this problem coming(service side or in your ASP .NET code).


Thanks,
Anil
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900