microsoft / microsoft/vssdktestfx

Class with multiple tests using MockedVSCollection and `GlobalServiceProvider` don't run all on VS

Open
#22 1 comment 0 reactions 1 assignee View on GitHub

@AArnott is already working on this.

Since Sep 1, 2026.

Dominant language
C#
Stars
22
Forks
9
Avg merge
3d 19h
Merged PRs (30d)
5

Description

In a test project in VS, If I 'Run All' Tests from the class in VS, there are some random failing tests with the following message:

image

Message: 
    System.AggregateException : One or more errors occurred.
    ---- System.InvalidOperationException : Cannot create more than one System.Windows.Application instance in the same AppDomain.
    ---- The following constructor parameters did not have matching fixture data: GlobalServiceProvider gsp

  Stack Trace: 
    ----- Inner Stack Trace #1 (System.InvalidOperationException) -----
    Application.ctor()
    OleServiceProviderMock.MainThread()
    --- End of stack trace from previous location where exception was thrown ---
    TaskAwaiter.ThrowForNonSuccess(Task task)
    TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    OleServiceProviderMock.ctor()
    GlobalServiceProvider.ctor()
    ----- Inner Stack Trace #2 (Xunit.Sdk.TestClassException) -----
Code
Test class
using Microsoft.VisualStudio.Sdk.TestFramework;
using Xunit;

namespace LibForVsSdk.Tests
{
    [Collection("LibForVsSdk.Tests.Test")]
    public class UnitTest1
    {
        public UnitTest1(GlobalServiceProvider gsp)
        {
        }

        [Fact]
        public void TestFalse()
        {
            Assert.False(false);
        }

        [Fact]
        public void TestTrue()
        {
            Assert.True(true);
        }

        [Theory]
        [InlineData(1)]
        [InlineData(2)]
        [InlineData(3)]
        public void Test1(int number)
        {
            Assert.True(number < 10);
        }
    }
}
Collection definition
using Microsoft.VisualStudio.Sdk.TestFramework;
using Xunit;

namespace LibForVsSdk.Tests
{
    [CollectionDefinition("LibForVsSdk.Tests.Test")]
    public class CollectionDef : ICollectionFixture<GlobalServiceProvider>
    {
    }
}
Test Project file
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net472</TargetFramework>
    <Nullable>enable</Nullable>
	  <LangVersion>latest</LangVersion>
    <IsPackable>false</IsPackable>
  </PropertyGroup>

  <ItemGroup>
	  <PackageReference Include="Microsoft.VisualStudio.Sdk.TestFramework" Version="17.0.15" />
	  <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
    <PackageReference Include="xunit" Version="2.4.1" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="coverlet.collector" Version="3.1.0">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
  </ItemGroup>

</Project>

Am I doing something wrong?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.