Note that there are some explanatory texts on larger screens.

plurals
  1. PONullReferenceException on Package Wizard's integration tests
    primarykey
    data
    text
    <p>I used Visual Studio 2010 SP1 and the package wizard to generate unit tests for an extension. The unit tests pass but the integration test (unmodified) fails on the UIThreadInvoker.Invoke call with a NullReferenceException. I added a menu and a toolwindow with the checkboxes in the wizard. </p> <p>Test method VSPackage2_IntegrationTests.IntegrationTests.CSharpProjectTests.WinformsApplication threw exception: System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.VSSDK.Tools.VsIdeTesting.UIThreadInvoker.Invoke(Delegate method) in f:\dd\VSSDK\VSIntegration\Tools\src\IDEHostAdapter\Framework\UIThreadInvoker.cs: line 44 at VSPackage2_IntegrationTests.IntegrationTests.CSharpProjectTests.WinformsApplication() in CSharpProjectTests.cs: line 62</p> <pre><code>using System; using System.Text; using System.Collections.Generic; using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.VsSDK.IntegrationTestLibrary; using Microsoft.VSSDK.Tools.VsIdeTesting; namespace VSPackage2_IntegrationTests.IntegrationTests { [TestClass] public class CSharpProjectTests { #region fields private delegate void ThreadInvoker(); private TestContext _testContext; #endregion #region properties /// &lt;summary&gt; ///Gets or sets the test context which provides ///information about and functionality for the current test run. ///&lt;/summary&gt; public TestContext TestContext { get { return _testContext; } set { _testContext = value; } } #endregion #region ctors public CSharpProjectTests() { } #endregion #region Additional test attributes // // You can use the following additional attributes as you write your tests: // // Use ClassInitialize to run code before running the first test in the class // [ClassInitialize()] // public static void MyClassInitialize(TestContext testContext) { } // // Use ClassCleanup to run code after all tests in a class have run // [ClassCleanup()] // public static void MyClassCleanup() { } // // Use TestInitialize to run code before running each test // [TestInitialize()] // public void MyTestInitialize() { } // // Use TestCleanup to run code after each test has run // [TestCleanup()] // public void MyTestCleanup() { } // #endregion [TestMethod] [HostType("VS IDE")] public void WinformsApplication() { UIThreadInvoker.Invoke((ThreadInvoker)delegate() { TestUtils testUtils = new TestUtils(); testUtils.CreateEmptySolution(TestContext.TestDir, "CSWinApp"); Assert.AreEqual&lt;int&gt;(0, testUtils.ProjectCount()); //Create Winforms application project //TestUtils.CreateProjectFromTemplate("MyWindowsApp", "Windows Application", "CSharp", false); //Assert.AreEqual&lt;int&gt;(1, TestUtils.ProjectCount()); //TODO Verify that we can debug launch the application //TODO Set Break point and verify that will hit //TODO Verify Adding new project item to project }); } } </code></pre> <p>}</p> <p>There is no source for UIThreadInvoker.cs to see where the null exception happens... I must have done something wrong in the setup so I reinstalled the SDK to no avail. I also used the package wizard again to double check, the second solution gets the same errors. I have tried commenting out all and part of the content of the delegate but it still fails. All other integration tests also fail with the same error in the same location.</p> <p>EDIT: Upon working further on this issue, I have modified the initial portion of the test to read:</p> <pre><code>[TestMethod] [HostType("VS IDE")] public void PackageLoadTest() { UIThreadInvoker.Initialize(); UIThreadInvoker.Invoke((ThreadInvoker)OnThreadInvoker); } private void OnThreadInvoker() { TestUtils testUtils = new TestUtils(); testUtils.CreateEmptySolution(TestContext.TestDir, "CSWinApp"); .... } </code></pre> <p>In the debugger it gets to the CreateEmptySolution method which eventually uses VsIdeTestHostContext.ServiceProvider, which is null. In fact, the VsIdeTestHostContext appears to be uninitialized. I cannot find a way to initialize it however. For some reason the VS IDE host type doesn't appear to be starting up, or at least not in time.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload