gpt4 book ai didi

c# - 调试 List.Count 抛出 ArgumentException

转载 作者:太空宇宙 更新时间:2023-11-03 13:58:33 25 4
gpt4 key购买 nike

我有外部类Item,如果我做:

List<Item> items = new List<Item>();

在调试期间将鼠标悬停在其上显示

'items.Count' threw an exception of type 'System.ArgumentException' int {System.ArgumentException}

我不能分享这个类的全部代码,但可能是什么原因。我反编译了类,发现有 GetHashCode 和 Equals 方法被覆盖。这可能是一个原因吗?

编辑:

调试中,行后

List<Item> items = new List<Item>();

使用立即窗口并在那里写入项目。我得到的计数:

'items.Count' threw an exception of type 'System.ArgumentException'
base {System.SystemException}: {"Cannot find the method on the object instance."}
Message: "Cannot find the method on the object instance."
ParamName: null

最佳答案

快速查看 ILSpy 或 Reflector 表明 List<T>.Count不可能引发该异常。

/// <summary>Gets the number of elements actually contained in the
/// <see cref="T:System.Collections.Generic.List`1" />.</summary>
/// <returns>The number of elements actually contained in the
/// <see cref="T:System.Collections.Generic.List`1" />.</returns>
public int Count
{
get { return this._size; }
}

鉴于您在调试期间收到此消息,我相信您有导致此异常的第 3 方控件或插件。尝试清理/重建、重新添加第 3 方引用和/或运行 Visual Studio in safe mode .

关于c# - 调试 List<T>.Count 抛出 ArgumentException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11364595/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com