It is conspicuous that the EnvDTE80.ErrorItems collection introduced by VS 2005 lacks an Add method to add errors to the ErrorList, so it was a common belief, apparently even within Microsoft and also mine until recently that only SDK packages can add errors to the ErrorList. There is good news: there is not only one approach, but two!
The first one was explained by Dave Sexton in this forum post and it uses the OutputWindowPane.OutputTaskItemString method but has some limitations.
I was investigating another approach and it was not until today that I became aware of the difference between GetService (that didn’t work in my sample) and GetGlobalService 🙂
Of course there is always in the VS automation world something else that doesn’t work as expected such as a +1 line number offset that others have posted in the MSDN forum more than once, but I managed to work around it.
So, here is the second working approach:
HOWTO: Add an error with navigation to the Error List from a Visual Studio add-in
http://www.mztools.com/articles/2008/MZ2008022.aspx
I always get the feeling that the automation model (EnvDTE) should be much more powerful and intuitive (no ErrorItems.Add method but OutputWindowPane.OutputTaskItemString to add errors to the Error List???) than what it is, and that the bridge between the automation model and the SDK is much more complicated that it should be (EnvDTE.DTE lacking a GetService method, assemblies that are only in the GAC or that you need to get installing the SDK that I don’t want to install, IVSHierarchy <-> EnvDTE.Project conversions, 0-based collections vs 1-based collections, etc.). The result is several hours spent making something simple work…
I use this implementation in my C# Addin for VS2010 and it work well on WinXP and Win7 32/64 Systems.
But on Win Server 2008 R2 it dosnt work.
There is always an Exception about ‘NullReferenceExeption’ in ‘Solution.GetProjectOfUniqueName(objProject.UniqueName, out objVsHierarchy)’ at objVsHierarchy.
I have no Idea why this Exception is only on Server and how can I workaround it.
Hello again,
I must correct my last comment. Not that call fails it is
objService = Microsoft.VisualStudio.Shell.Package.GetGlobalService(serviceType) in the GetService method that return no object