coverlet icon indicating copy to clipboard operation
coverlet copied to clipboard

AssemblyResolutionException for Microsoft.AspNetCore.Http.Features which exists in refs folder

Open agent019 opened this issue 2 years ago • 6 comments

Problem:

Code coverage not showing up for primary project dll.

Analysis:

Project file is a .NET Core 6 MVC Webapp. We have a dependency on the Microsoft.AspNetCore.App framework.

Error is the following: TpTrace Warning: 0 : 10244, 1, 2022/05/02, 13:29:05.588, 139093313616, datacollector.dll, [coverlet]Unable to instrument module: C:\dev\ocp\identity-provider\IdentityProvider.UnitTests\bin\Release\net6.0\IdentityProvider.dll because : AssemblyResolutionException for 'Microsoft.AspNetCore.Http.Features, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Try to add <PreserveCompilationContext>true</PreserveCompilationContext> to test projects </PropertyGroup> or pass '/p:CopyLocalLockFileAssemblies=true' option to the 'dotnet test' command-line

I've added the <PreserveCompilationContext>true</PreservceCompilationContext> to our test project. This forces the framework dll's to exist in bin\Release\net6.0\refs, but the error persists, as Microsoft.AspNetCore.Http.Features now only lives in that refs folder instead of one folder above.

This issue is likely caused by a breaking change to this assembly: https://docs.microsoft.com/en-us/dotnet/core/compatibility/aspnet-core/6.0/microsoft-aspnetcore-http-features-package-split

Workaround:

This issue can be resolved by moving the Microsoft.AspNetCore.Http.Features.dll file from the refs folder into the net6.0 folder one level above it.

This workaround is much more difficult in our CI pipeline.

Extra notes:

Here's the command we're running: dotnet test -p:Version=1.0.0 -p:CopyLocalLockFileAssemblies=true --no-restore --configuration release --settings ./pipeline-tests.runsettings --verbosity n --diag:log.txt --logger:"trx;logfilename=out.trx" --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover

I've attached the diagnostic log files, from before moving the assembly and after.

log.datacollector.after-moved-assembly.txt

log.datacollector.before-moved-assembly.txt

agent019 avatar May 02 '22 20:05 agent019

Thanks for reporting this.

MarcoRossignoli avatar May 24 '22 06:05 MarcoRossignoli

Has anyone had a chance to look at this? I am running into this as well, and the workaround does present an odd issue for CI builds.

spyder007 avatar Jan 05 '23 23:01 spyder007

I'm also encountering this issue. I can confirm that setting PreserveCompilationContext on the test project and then manually copying the Microsoft.AspNetCore.Mvc.ViewFeatures.dll out of the refs folder into the net6.0 works. Anyone come up with any other solutions?

randyshoopman avatar Feb 04 '23 00:02 randyshoopman

Until there's a fix for this issue here is what I'm adding to my test project (csproj) to resolve. Alternatively you could use <Exec Command="xcopy ..> instead of <Copy>

<PropertyGroup Condition=" '$(CollectCoverage)' == 'true' ">
  <PreserveCompilationContext>true</PreserveCompilationContext>
</PropertyGroup>

<!--...-->

<Target Name="FixCodeCoverage" AfterTargets="Build" Condition=" '$(CollectCoverage)' == 'true' ">
  <Warning Text="Fixing Coverlet Microsoft.AspNetCore.Mvc.ViewFeatures.dll issue: https://github.com/coverlet-coverage/coverlet/issues/1328"></Warning>
  <Copy
    SourceFiles="$(ProjectDir)$(OutputPath)refs\Microsoft.AspNetCore.Mvc.ViewFeatures.dll"
    DestinationFolder="$(ProjectDir)$(OutputPath)"
        />
</Target>

randyshoopman avatar Feb 06 '23 19:02 randyshoopman

See this issue. Seems related

BlackGad avatar Mar 15 '23 09:03 BlackGad

This issue is stale because it has been open for 3 months with no activity.

github-actions[bot] avatar Sep 04 '23 00:09 github-actions[bot]