Windbg “调试”;已添加具有相同密钥的项";例外

Windbg “调试”;已添加具有相同密钥的项";例外,windbg,Windbg,当我得到“已添加具有相同密钥的项”异常时,我的应用程序崩溃转储。我需要帮助查找导致此异常的对象。我可以打印异常,但无法找到导致异常的确切密钥。这可能是您的状态: [...] (3250.7ec): CLR exception - code e0434352 (!!! second chance !!!) [...] 0:000> .loadby sos clr 0:000> !pe Exception object: 030c31e8 Exception type: System

当我得到“已添加具有相同密钥的项”异常时,我的应用程序崩溃转储。我需要帮助查找导致此异常的对象。我可以打印异常,但无法找到导致异常的确切密钥。

这可能是您的状态:

[...]
(3250.7ec): CLR exception - code e0434352 (!!! second chance !!!)
[...]
0:000> .loadby sos clr
0:000> !pe
Exception object: 030c31e8
Exception type:   System.ArgumentException
Message:          An item with the same key has already been added.
InnerException:   <none>
StackTrace (generated):
    SP       IP       Function
    010FEE1C 6045F705 mscorlib_ni!System.ThrowHelper.ThrowArgumentException(System.ExceptionResource)+0x35
    010FEE2C 609410C7 mscorlib_ni!System.Collections.Generic.Dictionary`2[[System.__Canon, mscorlib],[System.__Canon, mscorlib]].Insert(System.__Canon, System.__Canon, Boolean)+0xc6af67
    010FEE60 5FD4B310 mscorlib_ni!System.Collections.Generic.Dictionary`2[[System.__Canon, mscorlib],[System.__Canon, mscorlib]].Add(System.__Canon, System.__Canon)+0x10
    010FEE68 017004F5 KeyAlreadyAdded!KeyAlreadyAdded.Program.Main()+0x45
[...]
Insert()
方法中,您可以使用
ebx
寄存器获取密钥:

0:000> .frame /r 4
04 010fee50 5fd4b310 mscorlib_ni![COLD] System.Collections.Generic.Dictionary`2[System.__Canon,System.__Canon].Insert(System.__Canon, System.__Canon, Boolean)$##6003922+0x87
eax=010fec58 ebx=030c2364 ecx=00000005 edx=00000000 esi=030c23b0 edi=030c2364
[...]

0:000> !do 030c2364
Name:        System.String
MethodTable: 5fdefd60
EEClass:     5f9c4e90
Size:        22(0x16) bytes
File:        C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll
String:      this
[...]
因此,在本例中,添加的重复键是字符串“this”。代码如下:

using System.Collections.Generic;

namespace KeyAlreadyAdded
{
    class Program
    {
        static Dictionary<string, string> dict = new Dictionary<string, string> {{"this", "was already inside"}};
        static void Main()
        {
            dict.Add("that", "goes in easily");
            dict.Add("this", "however, causes a duplicate key exception");
        }
    }
}
使用System.Collections.Generic;
已添加命名空间键
{
班级计划
{
静态字典dict=新字典{{“this”,“已在”}内;
静态void Main()
{
dict.Add(“那”、“很容易进去”);
dict.Add(“但是,这会导致重复密钥异常”);
}
}
}

这可能是您的状态:

[...]
(3250.7ec): CLR exception - code e0434352 (!!! second chance !!!)
[...]
0:000> .loadby sos clr
0:000> !pe
Exception object: 030c31e8
Exception type:   System.ArgumentException
Message:          An item with the same key has already been added.
InnerException:   <none>
StackTrace (generated):
    SP       IP       Function
    010FEE1C 6045F705 mscorlib_ni!System.ThrowHelper.ThrowArgumentException(System.ExceptionResource)+0x35
    010FEE2C 609410C7 mscorlib_ni!System.Collections.Generic.Dictionary`2[[System.__Canon, mscorlib],[System.__Canon, mscorlib]].Insert(System.__Canon, System.__Canon, Boolean)+0xc6af67
    010FEE60 5FD4B310 mscorlib_ni!System.Collections.Generic.Dictionary`2[[System.__Canon, mscorlib],[System.__Canon, mscorlib]].Add(System.__Canon, System.__Canon)+0x10
    010FEE68 017004F5 KeyAlreadyAdded!KeyAlreadyAdded.Program.Main()+0x45
[...]
Insert()
方法中,您可以使用
ebx
寄存器获取密钥:

0:000> .frame /r 4
04 010fee50 5fd4b310 mscorlib_ni![COLD] System.Collections.Generic.Dictionary`2[System.__Canon,System.__Canon].Insert(System.__Canon, System.__Canon, Boolean)$##6003922+0x87
eax=010fec58 ebx=030c2364 ecx=00000005 edx=00000000 esi=030c23b0 edi=030c2364
[...]

0:000> !do 030c2364
Name:        System.String
MethodTable: 5fdefd60
EEClass:     5f9c4e90
Size:        22(0x16) bytes
File:        C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll
String:      this
[...]
因此,在本例中,添加的重复键是字符串“this”。代码如下:

using System.Collections.Generic;

namespace KeyAlreadyAdded
{
    class Program
    {
        static Dictionary<string, string> dict = new Dictionary<string, string> {{"this", "was already inside"}};
        static void Main()
        {
            dict.Add("that", "goes in easily");
            dict.Add("this", "however, causes a duplicate key exception");
        }
    }
}
使用System.Collections.Generic;
已添加命名空间键
{
班级计划
{
静态字典dict=新字典{{“this”,“已在”}内;
静态void Main()
{
dict.Add(“那”、“很容易进去”);
dict.Add(“但是,这会导致重复密钥异常”);
}
}
}

如何查找词典的内容?如何查找词典的内容?