1

I have Win7 64 bits, Visual Studio 2010, and I have developed an Addin for Vs2010.

I try show messages in Error List Windows VS.
I use ErrorListProvider in OnBuildProjConfigDone build event for Addin

this._buildEvents.OnBuildProjConfigDone += new _dispBuildEvents_OnBuildProjConfigDoneEventHandler(_buildEvents_OnBuildProjConfigDone);

I get this error InvalidOperationException

The service 'Microsoft.VisualStudio.Shell.Interop.IVsTaskList' must be installed for this feature to work. Ensure that this service is available.

Connect

 public partial class Connect : IDTExtensibility2, IDTCommandTarget, System.Windows.Forms.IWin32Window, IOleCommandTarget

OnBuildProjConfigDone

void _buildEvents_OnBuildProjConfigDone(string project, string projectConfig, string platform, string solutionConfig, bool success)
{

// Omitted
 if (!resul)
 {
                project.DTE.ExecuteCommand("Build.Cancel");

                var errorListHelper = new ErrorListHelper();
                ErrorListProvider errorProvider = errorListHelper.GetErrorListProvider();
                var newError = new ErrorTask();
                newError.ErrorCategory = TaskErrorCategory.Message;
                newError.Category = TaskCategory.BuildCompile;
                newError.Text = "Cualquier mensaje de error aqui";
                errorProvider.Tasks.Add(newError);
 }
}      

ErrorListHelper

public class ErrorListHelper : System.IServiceProvider
{
    public ErrorListProvider GetErrorListProvider()
    {
        ErrorListProvider provider = new ErrorListProvider(this);
        provider.ProviderName = "Provider";
        provider.ProviderGuid = System.Guid.NewGuid();
        return provider;
    }

    public object GetService(Type serviceType)
    {
        return Package.GetGlobalService(serviceType);
    }
}

Suggestion by @JohnL: I put a breakpoint in my GetService method and Package.GetGlobalService is returning null.

Any suggestions?

Kiquenet
  • 14,494
  • 35
  • 148
  • 243
  • That's bizarre, I was just about to post a question about this exact problem (or, at least, I think it's the same problem). In my case, `errorProvider.Tasks.Add` is throwing `InvalidOperationException`, with that error message. Could you put a breakpoint in your `GetService` method and see if `Package.GetGlobalService` is returning null? Ta! – JohnL Dec 05 '12 at 11:06
  • Just that I've confirmed that the same code works in VS2008, and in a 2010 VSPackage. (with slight modifications because Package already has a GetService method). It's possible that VS2010 requires a slightly different GetService implementation. – JohnL Dec 10 '12 at 10:11

1 Answers1

0

Ryan Molden (MSFT) says:

Package.GetGlobalService is relying on at least one MPF package (from the specific version of MPF you are referencing) having been loaded. Since you yourself are an AddIn not a Package you can't guarantee that in any way.

You should pass something like new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider))) as the argument to ErrorListProvide

Package.GetGlobalService is returning null.

I use this code in my Addin. I test it and I get not error, and I can show errors and warnings in ErrorList Windows VS. I'll testing more for safely.

 public partial class Connect
    {
        ErrorListProvider _errorListProvider = null;

        void CreateErrorListProvider()
        {
            if (_errorListProvider == null)
            {
                System.IServiceProvider serviceProvider = new ServiceProvider(_applicationObject as Microsoft.VisualStudio.OLE.Interop.IServiceProvider);
                _errorListProvider = new ErrorListProvider(serviceProvider);
                _errorListProvider.ProviderName = "custom Errors";
                _errorListProvider.ProviderGuid = new Guid("xxxxxxxxxxxxxx");

            }
        }
Kiquenet
  • 14,494
  • 35
  • 148
  • 243