c# - 调用 EnvDTE80.ErrorItems.item() 时获取 "Index was outside the bounds of the array."

标签 c# visual-studio envdte

我试图在 Visual Studio 2015 错误列表窗口中获取所有错误,但在尝试通过 errors.Item(i) 调用访问 ErrorItem 时,我遇到了索引超出范围的异常。我是否缺少任何类型转换?

EnvDTE80.DTE2 dte2 =  ServiceProvider.GetService(typeof(EnvDTE.DTE)) as DTE2);
ErrorItems errors = dte2.ToolWindows.ErrorList.ErrorItems;
for (int i = 0; i < errors.Count; i++)
{
    ErrorItem item = errors.Item(i);
}

最佳答案

ErrorItems.Item 方法似乎需要一个绝对索引,从 1 开始,因此将循环更改为:

for (int i = 1; i <= errors.Count; i++)

那么它应该可以工作了。

关于c# - 调用 EnvDTE80.ErrorItems.item() 时获取 "Index was outside the bounds of the array.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42159829/

相关文章:

c# - 使用简单注入(inject)器和 WebForms MVP 将运行时值传递给构造函数

c# - 在 ASP.NET 问题中使用 jQuery AjaxForm

c# - 通过列表从 XML 中获取 InnerText

visual-studio - 如何在 Visual Studio 2019 中关闭自动缩进? (不是 Visual Studio Code )

c++ - 集成 Qt 框架、Netbeans IDE、Visual Studio C++ 编译器

c# - .ToUpper() 是如何工作的?

javascript - 使用 Visual Studio 调试第三方 Javascript?

visual-studio - 获取 CodeElement 的 Access 属性

visual-c++ - Visual Studio 属性表中的平台工具集属性

c# - 在 EnvDTE 中重新加载卸载的项目