I want to extend the Error List in Visual studio 2015/2017,I only use the DTE can get the ErrorItem however the ErrorItem don'e contain the ErrorCode just like below, how can i get the error code? Thanks in advance!
Asked
Active
Viewed 486 times
3

Circle Hsiao
- 1,497
- 4
- 22
- 37

D.Andy
- 247
- 3
- 9
1 Answers
0
Yup, I also had this. Might be too late to help, but here you go:
var errorList = _dte.ToolWindows.ErrorList as IErrorList;
// placed in dictionary for easy access later
var entries = (errorList?.TableControl.Entries ?? Enumerable.Empty<ITableEntryHandle>())
.Select((e, i) => new { Entry = e, Index = i + 1 })
.ToDictionary(it => it.Index, it => it.Entry);
var errors = errorList.ErrorItems;
for (int i = 1; i <= errors.Count; i++)
{
ErrorItem error = errors.Item(i);
entries[i].TryGetValue("errorcode", out var errorCode);
var item = new
{
error.Column,
error.Description,
error.ErrorLevel,
error.FileName,
error.Line,
error.Project,
Code = errorCode
};
}

reckface
- 5,678
- 4
- 36
- 62
-
This code is not working for 2019. Did the object model change? dte.ToolWindows.ErrorList does not implement IErrorList. Do you have a solution? TY – as9876 Dec 21 '20 at 21:20
-
I've used this in 2019. What's your `_dte` object type? – reckface Dec 22 '20 at 13:30
-
interface EnvDTE80.DTE2 – as9876 Dec 22 '20 at 16:13
-
"Suspicious cast: there is no type in the solution which is inherited from both 'EnvDTE80.ErrorItems' and 'Microsoft.VisualStudio.Shell.IErrorList'" – as9876 Dec 22 '20 at 16:15
-
any solutions? ty – as9876 Feb 03 '21 at 20:57
-
11) As of VS 2019 16.8.3, the debugger shows that the System.Type of dte.ToolWindows.ErrorList is the class Microsoft.VisualStudio.ErrorListPkg.ErrorListWindow of package C:\Program Files (x86)\Microsoft Visual Studio\2019\
\Common7\IDE\CommonExtensions\Microsoft\ErrorList\Microsoft.VisualStudio.ErrorListPkg.dll – Carlos Quintero Feb 04 '21 at 12:39 -
12) Using ILSpy you can see that that class inherits from abstract class Microsoft.VisualStudio.ErrorListPkg.Shims.ErrorList which in turn implements several interfaces, among them Microsoft.VisualStudio.Shell.IErrorList from assembly Microsoft.VisualStudio.Shell.Framework, Version=16.0.0.0. So, it is out of question that dte.ToolWindows.ErrorList implements IErrorList. – Carlos Quintero Feb 04 '21 at 12:40
-
13) In fact I have verified that if in a package if you get the dte instance (correctly) calling base.GetService(typeof(EnvDTE.DTE)) as EnvDTE80.DTE2 the cast from dte.ToolWindows.ErrorList to IErrorList does work. – Carlos Quintero Feb 04 '21 at 12:40
-
14) Which brings us to the question of how are you getting the DTE instance, because if you are getting it incorrectly (say, via some automation GetObject and cousins) it doesn't work (a different scenario which brought me to this thread). – Carlos Quintero Feb 04 '21 at 12:40
-
5) Finally, if when you say "not working" it means that you are getting a COM error such as E_NOINTERFACE it's likely because in your package you are getting the DTE instance in a wrong manner (point #4) and since IErrorList is a .NET interface but not a COM interface, that cannot work when COM is introduced in the equation. – Carlos Quintero Feb 04 '21 at 16:23
-
Yes, I'm using GetObject or cousin. Not within an extension. Not sure why it should matter how we're getting the DTE2 object. DTE2 object is not null. It comes from C:\Program Files (x86)\Microsoft Visual Studio\2019\
\Common7\IDE\PublicAssemblies\envdte80.dll In ILSpy, its ToolsWindows.ErrorList does not inherit from Microsoft.VisualStudio.ErrorListPkg.Shims.ErrorList. Rather, it is an interface in EnvDTE80 (assembly and namespace) @CarlosQuintero – as9876 Feb 04 '21 at 22:42 -
Using Object Browser in VS for an actual extension, I get the same source dll: EnvDTE80.dll, not the one you mentioned. – as9876 Feb 04 '21 at 23:01
-
EnvDTE80.ErrorList, despite its name (not starting with "I"), is an interface, not a class. Most EnvDTE types are interfaces, not classes. So, within VS, which class does implement the EnvDTE80.ErrorList interface? It's Microsoft.VisualStudio.ErrorListPkg.Shims.ErrorListWindow, which inherits from abstract class Microsoft.VisualStudio.ErrorListPkg.Shims.ErrorList, which inherits from abstract class Microsoft.VisualStudio.ErrorListPkg.Shims.TaskListBase which implements, among other interfaces, EnvDTE80.ErrorList. – Carlos Quintero Feb 05 '21 at 07:44
-
The problem is that: 1) In an extension, dte.ToolWindows.ErrorList, somehow, returns an instance of a real .NET class (Microsoft.VisualStudio.ErrorListPkg.Shims.ErrorListWindow), which implements COM interfaces such as EnvDTE80.ErrorList (that doesn't matter), but being an instance of a true .NET class you can cast to the non-COM interface Microsoft.VisualStudio.Shell.IErrorList that it also implements. – Carlos Quintero Feb 05 '21 at 12:49
-
2) In an out-of-process script, dte.ToolWindows.ErrorList, unfortunately, returns an instance of System.__ComObject, which is a Runtime Callable Wrapper (RCW) that encapsulates the access to a COM interface (EnvDTE80.ErrorList). From the RCW you can get only COM interfaces, you cannot get the non-COM interface Microsoft.VisualStudio.Shell.IErrorList. – Carlos Quintero Feb 05 '21 at 13:01