Philip
Philip

Reputation: 1

NuGet Update failure in Visual Studio 2019

I am having an issue with NuGet in Visual Studio 2019 (v.16.9.0).

My Solutions are all ASP.NET MVC Web Apps. I run on a local LAN. In the NuGet Package Manager 'Allow NuGet to download packages' and 'Automatically check for missing packages during build are both selected. I am using Packages.Config for management and the source is https://api.nuget.org/v3/index.json. VS is able to communicate via the Windows Defender Firewall. The target framework is .NET 4.7.2

The first issue is that, when I do a package restore after deleting the packages in the folder, it shows this error:

The requested operation cannot be performed on a file with a user-mapped section open.

After I do the build, the files are being created correctly, including the new/existing DLLs. These replenished/refreshed DLLs work perfectly and the program runs. The strange part, however, is that the relevant NUPKG file has zero content (which is obviously triggering the error). The message eventually disappears after completion of the DLL downloads I assume. All good so far but with zero content in the NUPKG file.

When I now try to update a package things go awry, the Error List shows:

An error occurred while trying to restore packages. The file is not a valid nupkg. File path...

Then after a full restart of VS, I get this:

An error occurred while retrieving package metadata for 'ABC.3.5.0.2' from source 'I:....\packages'.

'ABC' being the first file in the package list. It therefore appears to be failing because the relevant NUPKG has no content.

I am able to paste any file freely to the packages folder and its sub-folders, indicating that there is no lock on the files. Also VS is able to write the rest of the package structure to the folder without issue.

I think this must mean that something is specifically locking/blocking the NUPKG files (or deleting their content during creation perhaps). A search reveals nothing that I can see.

I even tried creating a brand new solution. During creation, the identical error message above popped up a warning. I also tried a few other of my existing solutions and got the same result. I updated VS and then I even did a full VS reinstall to the latest version, all to no avail.

I first noticed the issue after defining dependencies during an Azure Web App deployment (the Azure deployment tool optionally allows for updates to NuGet packages). After the NuGet update failed I set the option to blank and deployed anyway, the idea being to manually update the packages later. I cannot be certain, but I think this is when I discovered the issue. Could this process have changed a VS config setting somewhere perhaps?

Before the reinstall I opened the devenv.exe.config from inside VS and changed the IPV6 setting to false. No luck, so I have changed it back. I also did a test on one of the packages, downloading the package from the NuGet site directly and replacing the VS downloaded version, but I get the same errors.

Install failed. Rolling back... 
Package 'System.Buffers 4.5.1' does not exist in project 'ClickAuth_Graph' Package 'System.Buffers 4.4.0' already exists in folder 'I:\My Drive\Backups\ClickAuth_Graph (01_03_21)\packages' Added package 'System.Buffers 4.4.0' to 'packages.config' Removing package 'System.Buffers 4.5.1' from folder 'I:\My Drive\Backups\ClickAuth_Graph (01_03_21)\packages' This file is not a valid nupkg. File path...\packages\System.Buffers.4.5.1.nupkg Central Directory Corrupt An attempt was made to move the file pointer before the beginning of the file. At line:1 char 1
•   Update-Package System.Buffers +CategoryInfo NotSpecified: (:) [Update-Package], Exception 
o   FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.UpdatePackageCommand

For the record, I have one stale NuGet package in the portfolio. I don't use GitHub, but a repository was set upfront. I have not recently committed anything to GitHub.

Upvotes: 0

Views: 6008

Answers (2)

Ronald Stevens
Ronald Stevens

Reputation: 1

Wow, I had the same, but the solution is truly to keep your development on your local drive as cloud drives somehow do not work well together with packages. Why?? Not really sure, but when I copied my project to my local drive it was working flawless.

Upvotes: 0

Mr Qian
Mr Qian

Reputation: 23740

What you described is in a mess. And please try the following suggestions:

1) first clean all nuget caches or delete all cache files under C:\Users\xxx\.nuget\packages and I:\My Drive\Backups\ClickAuth_Graph (01_03_21)\packages.

I think that you have download the valid nuget packages on it and if your local exists the same name,version nuget package, it will always use the local wrong nuget package. So you have to delete them and then download the right package from the nuget package source.

2) enter Tools-->Options-->Nuget Package Manager-->Package Sources and make sure that you have enabled nuget.org package source, and if you have other own feed which you want to use, also enable it.

If not, please try to close VS, delete nuget.config under C:\Users\xxx\AppData\Roaming\NuGet. And then restart VS to re-generate it. Then, re-add your own feed if you have it.

3) run update-package -reinstall under Tools-->Nuget Package Manager--> Package Manager Console and then also delete bin and obj folder of your project.

4) you could also try to disable Azure deployment tool

Besides, if you have other solution level nuget.config, please check whether its content is suitable for your project. And if it is useless, you could remove them.

Upvotes: 1

Related Questions