question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Implicit references fail transitively

See original GitHub issue

This issue is effectively the same issue @natemcmaster has reported in https://github.com/aspnet/Docs/issues/9490#issuecomment-442912739 for .NET Core 2.2 -> 3.0 migrations, but the regression goes back to at least 2.1 -> 2.2 upgrades as well:

Preview 1 Known Issue - workaround for NuGet/Home#7342 - projects which do not start with <Project Sdk="Microsoft.NET.Sdk.Web"> will get compiler or runtime errors due to missing Microsoft.AspNetCore.* assemblies. This is most often the case for test projects and class libraries.

Consider the following project structure:

Source
|
 \ WebApi
   |
   \ WebApi.csproj
Tests
|
 \ WebApi.Tests
  |
   \ WebApi.Tests.csproj

and the following definitions for WebApi.csproj and WebApi.Tests.csproj:

WebApi.csproj

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <!-- Implicit Version to avoid MSBuild targets warning -->
    <PackageReference Include="Microsoft.AspNetCore.All" />
    <!--<PackageReference Include="Microsoft.AspNetCore.All" Version="2.2.3" AllowExplicitVersion="true" />-->
</Project>

WebApi.Tests.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
    <PackageReference Include="xunit" Version="2.4.1" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
    </PackageReference>
  </ItemGroup>
  <ItemGroup>
    <!-- This could really be any ProjectReference that transitively references a metapackage -->
    <ProjectReference Include="..\WebApi\WebApi.csproj" />
  </ItemGroup>
</Project>

If you build the solution, Tests\WebApi.Tests\obj\project.assets.json will show references to Microsoft.AspNetCore.All metapackage for .NET Core 2.1

The only solution is to use AllowExplicitVersion="true":

<PackageReference Include="Microsoft.AspNetCore.All" Version="2.2.3" AllowExplicitVersion="true" />

The error message is:

Severity: Error		
Code: CS1705
Description: Assembly 'WebApi' with identity 'WebApi, Version=1.5.0.0, Culture=neutral, PublicKeyToken=null' uses 'Microsoft.AspNetCore.Mvc.ViewFeatures, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' which has a higher version than referenced assembly 'Microsoft.AspNetCore.Mvc.ViewFeatures' with identity 'Microsoft.AspNetCore.Mvc.ViewFeatures, Version=2.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
Project: WebApi.Tests
File: D:\source\John.Zabroski\Source\WebApi.Tests\CSC
Line:	 1
Suppression State: Active

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:17 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
dsplaistedcommented, Mar 28, 2019

The transitivity issue isn’t related to whether your project is clean. It’s just how the reference to ASP.NET works in .NET Core 2.2.

We’ve been iterating on how the ASP.NET dependency is expressed since .NET Core 1.0. While not ideal, the behavior in 2.2 is improved over 2.1, 2.0, etc. We’ve made some more fundamental changes for .NET Core 3.0, which we believe will be a big improvement and resolve the issues we’ve had in previous versions with how the ASP.NET dependency works.

1reaction
dsplaistedcommented, Mar 27, 2019

@jzabroski This scenario will be fixed in .NET Core 3.0, which will use FrameworkReferences which will flow transitively.

For 2.2, the ASP.NET Core PackageReference does not flow transitively. However, you should be able to add it to the test project (without a version number, the same as in the web project), and it should work correctly. Have you tried that?

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Disable transitive project reference in .NET Standard 2
Here ProjectA will have implicit reference to Newtosoft.Json library. Unfortunately there is no DisableTransitivePackagesReferences for ...
Read more >
When logic fails: Implicit transitive inference in humans
Transitive inference (TI) in animals (e.g., choosing A over C on the basis of knowing that A is better than B and B...
Read more >
Implicit Value Updating Explains Transitive Inference ...
The ordering begins to emerge when all pairs are presented in the second phase, but is disrupted by massed FG trials.
Read more >
When logic fails: implicit transitive inference in humans
Transitive inference (TI) in animals (e.g., choosing A over C on the basis of knowing that A is better than B and B...
Read more >
Changes in Implicit Resolution - Scala 3 - EPFL
The previous possibility of an implicit search failure due to shadowing (where an implicit is hidden by a nested definition) no longer applies....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found