Wednesday, 21 March 2012

Troubleshooting NuGet failing to load

Today I had the unfortunate circumstance for VS2010 to crash whilst I was working, nothing to big I thought, I've had this happen before.

I reopened VS went to open my solution and got the following message:

Microsoft Visual Studio
The 'NuGet.Tools.NuGetPackage, NuGet.Tools, Version=1.6.21215.9133, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' package did not load correctly.


Nuget is smegged :( I immediately thought to uninstall the extension and then reinstall it, same thing happened :(

I then, (looking back this was foolish as NuGet is shared), thought I know I just load it in VS11 that will work, it also errored.

Not cool, the error message however directs you to start VS with logging enabled by using the /log command argument and then to look at the activity log.  The activity log is located in your appdata roaming folder, simply stick %appdata%\Microsoft\VisualStudio\10.0\ActivityLog.xml into run or %appdata%\Microsoft\VisualStudio\11.0\ActivityLog.xml dependant on your VS version. This will then load a load of XML with the VS loading activity in it. After a bit of scrolling I came across this:
    <time>2012/03/21 09:49:33.568</time>
    <description>SetSite failed for packageSetSite failed for package</description>
    <errorinfo>The composition produced a single composition error, with 2 root causes. The root causes are provided below. Review the CompositionException.Errors property for more detailed information.   1) '.', hexadecimal value 0x00, is an invalid character. Line 1, position 1. Resulting in: An exception occurred while trying to create an instance of type 'NuGet.VisualStudio.VsSettings'.
Resulting in: Cannot activate part 'NuGet.VisualStudio.VsSettings'.
Element: NuGet.VisualStudio.VsSettings -->  NuGet.VisualStudio.VsSettings -->  CachedAssemblyCatalog
Resulting in: Cannot get export 'NuGet.VisualStudio.VsSettings (ContractName="NuGet.ISettings")' from part 'NuGet.VisualStudio.VsSettings'.
Element: NuGet.VisualStudio.VsSettings (ContractName="NuGet.ISettings") -->  CachedAssemblyCatalog
.........… rest removed due to length .........
The key information here is the invalid character and the NuGet.VisualStudio.VsSettings. This looks like the NuGet.Config is corrupt, the next question is where is it. Turns out this is also in app data %appdata%\nuget\ Once here I opened the file in notepad and found it was empty all bar the Unicode start file character.

To restore the file you just need to put in the location of package sources NuGet should use, the default is:

<?xml version="1.0" encoding="utf-8"?>
    <add key="NuGet official package source" value="" />
    <add key="NuGet official package source" value="" />
Once this was saved I tried running NuGet via the command prompt and got the familiar available commands listing.


A bit of a pain but the experience lead me to learning about the VS activity log which I'm sure will be useful to know in the future. Now time to get back on with my project....

1 comment:

  1. Very nice, love it when we're forced to debug VS... I've never had this particular problem with nuget, had others though :)