locked
VSPackage: Automatically generated test fails with: System.InvalidOperationException: The service 'Microsoft.VisualStudio.Shell.Interop.SVsActivityLog' must be installed for this feature to work. Ensure that this service is available RRS feed

  • Question

  • Hi,

    I have been investigating the possibility of creating a VSPackage extension to add support for another programming language to visual studio for my final computer science project before graduating university. I am a big fan of automated testing and was glad to see the custom editor template project had some options to automatically generate some test projects for me.


    The problem is that even without making a single code change to the code generated by the VSPackage wizard, three of the automatically generated tests fail. The first one I'm going to ask help with, because I suspect it might be leading to the other two, is testing the package's SetSite method. The code for the test is:

            [TestMethod()]
            public void SetSite()
            {
                // Create the package
                IVsPackage package = new BooLanguageExtensionPackage() as IVsPackage;
                Assert.IsNotNull(package, "The object does not implement IVsPackage");

                // Create a basic service provider
                OleServiceProvider serviceProvider = OleServiceProvider.CreateOleServiceProviderWithBasicServices();

                // Add site support to register editor factory
                BaseMock registerEditor = BooLanguageExtension_UnitTests.EditorTests.RegisterEditorsServiceMock.GetRegisterEditorsInstance();
                serviceProvider.AddService(typeof(SVsRegisterEditors), registerEditor, false);
                int hr = package.SetSite(serviceProvider);
                ErrorHandler.ThrowOnFailure(hr);
                // Site the package
                Assert.AreEqual(VSConstants.S_OK, hr, "SetSite did not return S_OK");

                hr = package.SetSite(null);
                // Unsite the package
                Assert.AreEqual(VSConstants.S_OK, hr, "SetSite(null) did not return S_OK");
            }

    The exception I get is: System.InvalidOperationException: The service 'Microsoft.VisualStudio.Shell.Interop.SVsActivityLog' must be installed for this feature to work. Ensure that this service is available. Using step through debugging I discovered the exception is thrown during the call to the SetSite method.

    Now if I understood my tutorials correctly, packages are not able to grab services like SVsActivityLog until after they've been sited into the visual studio IDE, which makes me wonder why someone is trying to access it already in the SetSite method itself. I double checked the BooLanguageExtensionPackage class it generated for me and it does not override the SetSite method, it inherits it from the Package class.

    Furthermore running the project directly it seems to work fine, I can see my package registered in the about window of the experimental hive. Is there perhaps something missing from the above generated code that needs to be done before the call to SetSite?


    I am working on VisualStudio 2013 Ultimate on a Windows 7 64 bit OS.

    Tuesday, December 24, 2013 3:51 PM

Answers

  • Hi Ghost314,

    I reproduced your issue and I think it is an issue of visual studio. Please reopen your thread on connect.

    Thank you for your understanding!

    • Marked as answer by Anna Cc Friday, January 3, 2014 2:50 AM
    Thursday, December 26, 2013 6:02 AM

All replies

  • Hi Ghost314,

    I reproduced your issue and I think it is an issue of visual studio. Please reopen your thread on connect.

    Thank you for your understanding!

    • Marked as answer by Anna Cc Friday, January 3, 2014 2:50 AM
    Thursday, December 26, 2013 6:02 AM
  • I ran into the same issue. Adding a mocked IVsActivityLog to the test's OleServiceProvider seems to do the trick, at least to get the test to pass.

    After the OleServiceProvider is instantiated, add the following two statements:

    BaseMock activityLogMock =
        new GenericMockFactory(
            "MockVsActivityLog",
            new[] {typeof (Microsoft.VisualStudio.Shell.Interop.IVsActivityLog)}
            ).GetInstance();
    
    serviceProvider.AddService(
        typeof (Microsoft.VisualStudio.Shell.Interop.SVsActivityLog),
        activityLogMock,
        true);

    Again, at a glance, the test passes. Any calls to the mock object are being discarded rather than logged, but since it looks like all the calls return 0 / S_OK on success (msdn doc link below), and the empty mock should be returning exactly that (default(int)), any code that calls to it should succeed.

    http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.interop.ivsactivitylog.aspx

    • Proposed as answer by dronechip Wednesday, March 5, 2014 11:14 PM
    Wednesday, March 5, 2014 11:02 PM
  • I ran into the same issue. Adding a mocked IVsActivityLog to the test's OleServiceProvider seems to do the trick, at least to get the test to pass.

    After the OleServiceProvider is instantiated, add the following two statements:

    BaseMock activityLogMock =
        new GenericMockFactory(
            "MockVsActivityLog",
            new[] {typeof (Microsoft.VisualStudio.Shell.Interop.IVsActivityLog)}
            ).GetInstance();
    
    serviceProvider.AddService(
        typeof (Microsoft.VisualStudio.Shell.Interop.SVsActivityLog),
        activityLogMock,
        true);

    Again, at a glance, the test passes. Any calls to the mock object are being discarded rather than logged, but since it looks like all the calls return 0 / S_OK on success (msdn doc link below), and the empty mock should be returning exactly that (default(int)), any code that calls to it should succeed.

    http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.interop.ivsactivitylog.aspx

    That fails with the Managed Package Framework in the SolutionListener class:

    Debug.Assert(this.solution != null, "Could not get the IVsSolution object from the services exposed by this project");


    MickyD | <a href="http://mickyd.wordpress.com/">http://mickyd.wordpress.com/</a> Help others by voting my post as 'Helpful' if you think it is so.

    Tuesday, April 7, 2015 8:28 AM