Search code examples
c#.netmigrationautofac.net-6.0

All tests are inconclusive with the same "An assembly specified in the application dependencies manifest was not found" error when migrating to .NET 6


I'm migrating from .NET 5 and all tests are working, and finishing succesfully, until I update all .csproj files to .NET 6.0 like this:

  <PropertyGroup>
      <TargetFramework>net6.0</TargetFramework>
  </PropertyGroup>

Afterwards all integration and unit tests show as inconclusive in Rider with the following error:

Test not run

Last runner error: Test runner agent exited unexpectedly Process /usr/share/dotnet/dotnet:138437 exited with code '140': Error: An assembly specified in the application dependencies manifest (Logging.UnitTests.deps.json) was not found: package: 'Autofac', version: '6.4.0' path: 'lib/net6.0/Autofac.dll'

--- EXCEPTION #1/3 [UnknownExitCodeException]
Message = “
  Process /usr/share/dotnet/dotnet:138437 exited with code '140':
  Error:
    An assembly specified in the application dependencies manifest (Logging.UnitTests.deps.json) was not found:
      package: 'Autofac', version: '6.4.0'
      path: 'lib/net6.0/Autofac.dll'
”

I have tried updating all nuget packages, including autofac, to the latest version, tried all possible combinations with Autofac, but the error still remains. I'm on Arch linux and have all the correct dotnet sdks and runtimes.

dotnet --list-sdks
5.0.407 [/usr/share/dotnet/sdk]
6.0.102 [/usr/share/dotnet/sdk]
6.0.301 [/usr/share/dotnet/sdk]

dotnet --list-runtimes
Microsoft.AspNetCore.App 5.0.16 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.6 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 5.0.16 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.2 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.6 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

The application runs normally in both Run and Debug mode, it's just that all tests have stopped working. This also happens in the GitHub pipeline, any ideas?

Thank you very much in advance!


Solution

  • So after many hours finding a fix I tried the following:

    • Create a new .NET 6 test project
    • See if a small test without dependencies works, and it did work.
    • Look at the NuGet package references that were automatically added to that test project
    • Look at the NuGet package refences in the tests projects that were failing
    • Realize some were only implicitly referenced, remember how this has @$%^ me in the ^&%$ in the past
    • Directly reference "Microsoft.NET.Test.Sdk" and "xunit" in every test project like this:
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
    <PackageReference Include="xunit" Version="2.4.1" />
    
    • Witness how all tests are running correctly again.

    TL;DR, add the following to every test project you have:

      <ItemGroup>
          <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
          <PackageReference Include="xunit" Version="2.4.1" />
      </ItemGroup>