0

I deleted nuget cashe with command

nuget locals all -clear

After that, I couldn't run a project. My project is in ASP.NET Core 2. It shows this error message

 error : An error occurred while retrieving package metadata for 'Microsoft.Extensions.Caching.Memory.2.1.1' from source 'C:\Program Files\dotnet\sdk\NuGetFallbackFolder'

I tried dotnet restore, the same mistake. I tried to reinstall packages but nothing helps. Any suggestions for fixing this problem or explanation of the problem?

My project file contains :

<Reference Include="Microsoft.Extensions.Caching.Memory, Version=2.2.0.0, Culture=neutral, , processorArchitecture=MSIL"> 
 <HintPath>..\..\packages\Microsoft.Extensions.Caching.Memory.2.2.0\lib\netstandard2.0\Microsoft.Extensions.Caching.Memory.dll</HintPath> 
</Reference>
Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
  • The current version is 3.1.2. Do you have a hard-coded reference to `2.1.1` or that specific path? What does your `csproj` look like? Especially the `PackageReference` element that adds `Microsoft.Extensions.Caching.Memory` – Panagiotis Kanavos Mar 10 '20 at 09:17
  • The package may be added as an indirect reference. In that case, check `project.assets.json` in the `obj` folder. This file lists all dependencies hierarchically. – Panagiotis Kanavos Mar 10 '20 at 09:22
  • This is in csproj file ` ..\..\packages\Microsoft.Extensions.Caching.Memory.2.2.0\lib\netstandard2.0\Microsoft.Extensions.Caching.Memory.dll ` – Bogoljub V. Mar 10 '20 at 09:32
  • I believe you will find this answer from another user quite helpful. Give it a look: https://stackoverflow.com/a/37618663/8293694. In my opinion the 2 questions are similar. – vasilisdmr Mar 10 '20 at 09:36
  • In the question itself please! That's a problem though - it's a *direct* reference to a specific local file, not a `PackageReference`. How was this package added? – Panagiotis Kanavos Mar 10 '20 at 09:38

1 Answers1

0

It looks like the DLL was added manually, without actually adding the package. Or the project was migrated from the old .NET Framework format without moving the package references to it.

NuGet packages are added through the PackageReference tag. The project file should contain :

<ItemGroup>
    <!-- ... -->
    <PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="2.2.0" />
    <!-- ... -->
</ItemGroup>

Reference adds a reference to a local DLL. That DLL has to be present, either in the SDK or the local folder pointed by HintPath. In this case, the Reference tag should be removed.

Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236