0
votes

I'm receiving the following warning on my ASP.NET Core 2.1 MVC project.

C:\Program Files\dotnet\sdk\2.2.102\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets(153,5): warning NETSDK1071: A PackageReference to 'Microsoft.AspNetCore.App' specified a Version of 2.1.7. Specifying the version of this package is not recommended. For more information, see https://aka.ms/sdkimplicitrefs

It appears to be referencing this line in my .csproj file:

<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.7" />

If I remove the version from the PackageReference the warning goes away, but then I get this error when I try to start my project:

System.IO.FileLoadException: Could not load file or assembly 'Microsoft.AspNetCore.Mvc.Core, Version=2.1.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

File name: 'Microsoft.AspNetCore.Mvc.Core, Version=2.1.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'

at MyProject.Web.Startup.ConfigureServices(IServiceCollection services)

--- End of stack trace from previous location where exception was thrown ---

at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceCollection services)

at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices()

at Microsoft.AspNetCore.Hosting.Internal.WebHost.Initialize()

--- End of stack trace from previous location where exception was thrown ---

at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()

I'm not sure where Microsoft.AspNetCore.Mvc.Core, Version=2.1.3.0 is even coming from. Anyone else run into the same problem?

2
I too have this issue and was able to resolve it by adding the version to that package reference like <PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.3" />Craig Selbert
@Wellspring, Add your .csproj file code. I am telling you what the problem exactly is!TanvirArjel

2 Answers

2
votes

I'm still not sure what caused the problem, but to fix it I went ahead and updated from ASP.NET Core 2.1 to 2.2 by following this article.

Here's the relevant part of my .csproj after the update:

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

<ItemGroup>
    <!-- Other Unrelated Packages Here -->

    <PackageReference Include="Microsoft.AspNetCore.App" />

    <!-- Other Unrelated  Packages Here -->
</ItemGroup>

Then, I updated all of my NuGet packages to the latest version.

I imagine there's a solution without having to upgrade versions of ASP.NET Core, but since I don't have any reason not to upgrade, this is what I did to fix it.

1
votes

Add this

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.AspNetCore.Mvc.Core" publicKeyToken="adb9793829ddae60" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.7.0" newVersion="2.1.7.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>