30

I have been trying to update NuGet packages in Visual Studio 2019 from both package manager consoles and the manage NuGet packages from the context options, but in both cases I get "Found invalid data while decoding." error.

I have to revert to Visual Studio 2017 to update. Is there a way to deal with this or do I have to contend with this switching for now?

The error outputs are as below for both scenarios:

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
xariez
  • 529
  • 1
  • 5
  • 17
  • 1
    Clear your local NuGet cache? (See [here](https://learn.microsoft.com/en-us/nuget/consume-packages/managing-the-global-packages-and-cache-folders#clearing-local-folders) for details.) – Richard Apr 23 '19 at 08:26
  • @Richard still not helpful even after clearing cache – xariez Apr 23 '19 at 10:51
  • 1
    I found this could be a VS 2019 issue, and temporarily I make it work by removing obj folder and clearing all the cache. – cjcrobin May 08 '19 at 02:53
  • cjcrobin's comment above worked! I cleared the NuGet cache then after deleting the obj folder it worked. – Greesemonkey3 Aug 10 '19 at 18:43

2 Answers2

65

Visual Studio 2019

  1. Go to menu ToolsNuGet Package ManagerPackage Manager Console.
  2. Type dotnet nuget locals all --clear.
  3. Clean the solution.
  4. Delete the bin and obj folders from the project folder.

It is 100% working.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
CThru
  • 666
  • 6
  • 3
  • I had to do this twice, the second time I was more patient and let Visual Studio start-up and take its time to initialize completely before building. If you started a Clean or Build and Visual Studio seems like it is hanging, you can cancel the Build from the Build menu and then from the Visual Studio task list, in the bottom-left corner task list. – Martin Lottering May 03 '20 at 11:54
  • So many other posts and none of them worked. Thank you so much. This is why I hate admins that delete duplicate questions. That 'duplicate' question has slight differences that ultimately had different answers. This is exactly what I needed! – ModestMonk Aug 19 '20 at 15:09
  • Trying clicking every button in VS2019 ends into nothing helpful. Kind of curious how one can find the secret command line and save the world spoiled by GUI. It's so hard to find the info in Windows doc, but SO is the save. – silencej Sep 09 '20 at 02:46
  • Thank you very much! After 3 hours trying to solve this problem, i finally found your solution! – Daiana Sodré Sep 16 '20 at 12:20
  • Also works in Visual Studio 2022 – Jesper Mygind Nov 17 '21 at 12:56
  • `dotnet nuget locals all --clear` also fixed issue `error : '.', hexadecimal value 0x00, is an invalid character. Line 1, position 1.` Adding for search engine juice. I encounted this error when I was trying to use WSL / ubuntu and trying to use `dotnet build`. Thanks! – Eli Gassert Jun 01 '22 at 12:13
3

Deleting the obj and bin folders in each project in my solution, then reopening Visual Studio 2019 to trigger automatic package download worked for me. I don't think you need to remove bin as well but I was going crazy at that point.

Tim
  • 810
  • 9
  • 20