Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
agent019 opened this issue May 2, 2022 · 7 comments
Labels
stale untriaged To be investigated

Comments

@agent019
Copy link

agent019 commented May 2, 2022

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

@MarcoRossignoli
Copy link
Collaborator

Thanks for reporting this.

@MarcoRossignoli MarcoRossignoli added the untriaged To be investigated label May 24, 2022
@spyder007
Copy link

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.

@randyshoopman
Copy link

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
Copy link

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>

@BlackGad
Copy link
Contributor

See this issue. Seems related

@github-actions
Copy link

github-actions bot commented Sep 4, 2023

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

@github-actions github-actions bot added the stale label Sep 4, 2023
Copy link

github-actions bot commented Jun 9, 2024

This issue was closed because it has been inactive for 9 months since being marked as stale.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale untriaged To be investigated
Projects
None yet
Development

No branches or pull requests

5 participants