System.Collections.Generic.Key ... [英] System.Collections.Generic.Key...

查看:50
本文介绍了System.Collections.Generic.Key ...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web服务,并且正在将web服务引用到asp.net代码。我在asp.et页面中从服务器检索图像并将其加载到iframe但是我收到错误但是我找不到错误请建议。如何处理错误。



System.Collections.Generic.KeyNotFoundException:字典中没有给定的密钥。

在System.ThrowHelper.ThrowKeyNotFoundException()

at System.Collections.Generic.Dictionary`2.get_Item(TKey key)

at System.Data.DataView.GetRowView( Int32记录)

在System.Data.DataView.CopyTo(DataRowView []数组,Int32索引)

在System.Data.DataView.GetEnumerator()
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(对象发送者,EventArgs e)

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)

推荐答案

嗨Karthikeyan,





请参阅以下示例了解此类异常的发生方式。



Hi Karthikeyan,


See below example for how this type of exception occurs.

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();

            }

        }
    }
}







如果我们试图从字典中获取密钥1,2的值,它就可以正常工作。



我希望,现在你已经明白了这是怎么发生的。调试它并检查这个问题的来源(服务端或你的ASP .NET代码)。





谢谢,

Anil




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


这篇关于System.Collections.Generic.Key ...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆