title: Nuget Update failure in Visual Studio 2019
body: <p>I am having a strange (new) issue with Nuget in Visual Studio 2019 (v.16.9.0).</p>
  <p>The Solutions are all ASP.NET Web Apps (MVC). 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 <a href="https://api.nuget.org/v3/index.json" rel="nofollow noreferrer">https://api.nuget.org/v3/index.json</a>. VS is able to communicate via the Windows Defender Firewall. The target framework is .Net 4.7.2</p>
  <p>The first issue is when I do a package restore after deleting the packages in the folder, it shows this error: <em>The requested operation cannot be performed on a file with a user-mapped section open</em>.
  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.</p>
  <p>When I now try to update a package things go awry, the Error List shows:</p>
  <p><em>An error occurred while trying to restore packages. The file is not a valid nupkg. File path...</em></p>
  <p>Then after a full restart of VS, I get this:</p>
  <p><em>An error occurred while retrieving package metadata for 'ABC.3.5.0.2' from source 'I:....\packages'.</em> 'ABC' being the first file in the package list. It therefore appears to be failing because the relevant NUPKG has no content.</p>
  <p>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.</p>
  <p>IMHO 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.</p>
  <p>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.</p>
  <p>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?</p>
  <p>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.</p>
  <p><code>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</code></p>
  <p>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.</p>
  <p>Is there an expert out there that can help?</p>