0

I am having a strange (new) issue with Nuget in Visual Studio 2019 (v.16.9.0).

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 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 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.

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.

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.

Is there an expert out there that can help?

Philip
  • 1
  • 1
  • 4

2 Answers2

1

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.

Mr Qian
  • 21,064
  • 1
  • 31
  • 41
  • After I run update-package -reinstall update-package, I get: `The file is not a valid nupkg. File path: I:\My Drive\Backups\ClickAuth_Graph (03_03_21)\packages\Antlr.3.5.0.2\Antlr.3.5.0.2.nupkg At line:1 char:1 + update-package -reinstall + ~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Update-Package], InvalidDataException + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.UpdatePackageCommand` That was the first alphabetic package. – Philip Mar 05 '21 at 11:20
  • Once again the NUPKG size is 0. However, the restored cache files in `C:\Users\xxx\.nuget\packages` show NUPKGs that actually do have valid content. For some reason it is not copying the NUPKGs across correctly, but copying the DLLs etc correctly. All projects use standard Nuget config (which I renewed anyway). The Azure tool is not being used in the version I am testing. Process Explorer shows nothing hanging onto the project package folder. – Philip Mar 05 '21 at 11:37
  • From the log, the nupkgs are restored from `I:\My Drive\Backups\ClickAuth_Graph (03_03_21)\packages`. And the error is that the the nuget packages under that path are wrong. Did you try to delete all the files under that `packages` folder and then download the correct ones from `nuget.org`? Or you have a new `nuget.config` file above the project folder to use the nuget source `I:\My Drive\Backups\ClickAuth_Graph (03_03_21)\packages\`? – Mr Qian Mar 08 '21 at 02:04
  • And you should check the nuget package source and please [download the correct one from nuget.org](https://www.nuget.org/packages/Antlr/) and then put the right ones into the nuget package source. – Mr Qian Mar 08 '21 at 02:05
  • I had tried that, as you suggested already. In fact, the error log shown above is after a complete deletion of the local packages folder. In the reinstalled packages, I can see that ALL of the nupkg files have no content. I also tried deleting C:\Users\user\.nuget\packages and the packages get restored/downloaded correctly. However when the Nuget process copies them over to the local folder, the content of the nupkg element goes to zero. The DLLs themselves get copied perfectly and work. However you need the nupkg zip when updating, of course. Something is blocking the nuget zip... – Philip Mar 09 '21 at 08:28
  • Did you check your firewall or did you try to check whether some third party software prevent `nuget.org`? – Mr Qian Mar 09 '21 at 09:56
  • The firewall allows the packages through as they are being restored to the nuget\packages folder after clearing (all) caches. Some items (like the DLLs are being copied) so the folder is free. The problem is with the NUPKG zip file that is copied, but has no content because it is being blocked by the mapping issue. – Philip Mar 11 '21 at 08:25
  • Maybe you have to reset the Internet environment. – Mr Qian Mar 17 '21 at 07:32
  • The NUPKG's that land in C:\Users\user\.nuget\packages after a restore are perfect, so they are getting through correctly. It is in the copying process from the one packages folder to the other that there is a snarl-up. Thanks so much for all your help so far BTW! – Philip Mar 18 '21 at 09:24
  • Since we do not have the settings and of your complex environment, the fix process actually takes a long journey. Anyway, you have a workaround about your issue, you could add an answer to share your workaround. And it is kind of you to do that. And thanks for feedback. – Mr Qian Mar 19 '21 at 07:49
  • The issue is still not resolved. The packages restore perfectly when run on a separate device, so the issue is clearly not with the solution itself. You mentioned I should disable the Azure deployment tool. How would one do that? – Philip Apr 03 '21 at 09:25
  • 4
    Turns out the problem was that the project was saved on Google Drive. Answer by eryondon at MS: 'Using local drive syncs with cloud storage such as Google Drive for nuget package folder is not good practice. Even compiling/building code on it may bring up many unwanted hard to diagnose issues.The problem is race condition between Google sync app and VS, it’s not deterministic depending on speed of your disk, system load, internet speed etc. I would recommend you do all your development work actual local hdd drive such as ssd.' – Philip Apr 22 '21 at 15:44
  • Thanks! My problem fixed after deleting .nuget and \AppData\Roaming\NuGet\ – Houcheng Oct 01 '21 at 22:15
0

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.

  • My take is that the addresses get too lengthy. Since switching to using local drives only, I have not had any further issues of this nature. – Philip Aug 24 '23 at 16:04