When running a .NET 7 integration test, the testhost throws an error stating that Microsoft.TestPlatform. CommunicationUtilities.dll cannot be found, even though Microsoft.TestPlatform is referenced in the project.
What causes this missing assembly issue, and what steps are needed to resolve it so the integration test can run successfully?
Having dealt with similar issues in .NET 7 integration tests before, the first thing I’d check is whether your test project is using a compatible version of the test SDK. The missing Microsoft.TestPlatform.CommunicationUtilities assembly usually means the testhost didn’t pull the right dependencies.
Update your .csproj like this:
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
</ItemGroup>
Then run:
dotnet restore
dotnet build
dotnet test
This works because Microsoft.NET.Test.Sdk manages the testhost environment and ensures all required binaries—including CommunicationUtilities are copied correctly.
You’re absolutely right, @dipen-soni .And speaking from experience dealing with flaky dependency issues, even after updating the SDK, sometimes the NuGet cache itself becomes the culprit. A corrupted cached package can cause the missing Microsoft.TestPlatform.CommunicationUtilities assembly error to appear even when everything looks correct on paper.
Try clearing all NuGet caches:
dotnet nuget locals all --clear
dotnet restore
Once you rebuild, .NET will fetch a clean copy of every dependency, which often resolves cases where the right SDK is installed but the wrong testhost DLLs are being picked up.
Good points from both of you! I’ll add something I’ve run into while working across multiple machines. Even with the right SDK and a clean NuGet cache, mixing SDK or runtime versions can still break a .NET 7 integration test and trigger the same missing Microsoft.TestPlatform.CommunicationUtilities assembly error.
Verify your environment alignment:
dotnet --version
dotnet --list-sdks
dotnet --list-runtimes
And confirm your test project explicitly targets .NET 7:
<TargetFramework>net7.0</TargetFramework>
If your runner, SDK, or Visual Studio Test Explorer uses an older testhost, the dependencies won’t load properly. Making sure all three project, CLI, and runner are on .NET 7 usually eliminates the remaining edge cases.