Are you missing an assembly reference? Why, yes I am. So kind of you to ask.

Ever pull down the source code for a project, only to find many errors of the “The type or namespace name ‘Optimization’ does not exist in the namespace ‘System.Web’ (are you missing an assembly reference?)” variety?

This just happened to me because I pulled down the Page of Photos source code from github for the first time to a certain dev machine. Not all of the binary library dependencies are checked into github (trying to just check in source code), so how does this happen and how should it be fixed?

image

In my experience, this usually relates to NuGet packages. There are at least two reasonable solutions.

Solution #1: Capture All Binaries (not recommended)

Check into source control the binaries for those packages your project depend on so they’ll always be there. Personally, that seems so last year, and I don’t take this approach for libraries available through NuGet.

(Having private libraries is no longer a reason to do this either. Check out MyGet,org for a hosted private solution that works fine with NuGet machinery.)

Solution #2: Empower NuGet to Self-Heal

Right-click on the Solution from the Visual Studio Solution Explorer and notice the two NuGet-related options in the pop-up menu. To fix the problem imageat hand in the most convenient manner, simply select “Enable NuGet Package Restore” which is the second of the NuGet-related options.

You will then get an explanation of what’s about to happen:

image

If you choose “Yes” then NuGet will think for a few seconds before declaring victory:

image

You might notice there are some new NuGet-related artifacts in your solution.

image

Now if you again right-click on the Solution from Visual Studio’s Solution Explorer menu, you will notice that the “Enable NuGet Package Restore” menu is gone, leaving only the “Manage NuGet Packages for Solution” option. Select the “Enable NuGet Package Restore” menu to bring up the NuGet management dialog.

image

Click on “Restore” and your solution should begin to heal itself by downloading the many missing NuGet packages. You can feel the excitement as NuGet thinks it through..

image

.. and thinks some more ..

image

.. then – Ta Da! – you suddenly have a bunch of downloaded libraries.

image

Now your solution will happily compile once more.

Note that this is a one-time & long-term solution since now NuGet is empowered to pull down missing packages whenever needed. (Not “any old packages” of course – just those you’ve added to the projects within the solution.) When you freshly pull down a build (just the source) from source control it helps, of course, but build machines will also enjoy this.

8 thoughts on “Are you missing an assembly reference? Why, yes I am. So kind of you to ask.

  1. Pingback: Reading Notes 2013-09-09 | Matricis

  2. Pingback: Are you missing an assembly reference? Why, yes I am. So kind of you to ask. | TechCentral

  3. Ryan

    Thanks – I had tried this a few times with a project template that I had downloaded. Restore would appear to complete but references still showed up with warning triangles.

    Examining the references path showed that it was looking in “..\packages\…….” which didn’t match my structure. This is because I had created the new project with the checkbox ‘Create subfolder for solution name’ cleared. I started again with this box ticked, restored the missing nuget packages, and all appears to be working now.

    Reply
  4. Christi

    i like your title! I followed your directions, but when I came to the Manage NuGet Packages for Solution window, mine did not let me “restore”. (your directions said : Now if you again right-click on the Solution from Visual Studio’s Solution Explorer menu, you will notice that the “Enable NuGet Package Restore” menu is gone, leaving only the “Manage NuGet Packages for Solution” option. Select the “Enable NuGet Package Restore” menu to bring up the NuGet management dialog….. and yet I did not have “Enable NuGet Package Restore” menu, but only the “Manage NuGet Packages for Solution” option which I did select to get to the next window that did not give me the Restore button.) I did get a nuget.org link under online and I am working to find the libraries I need to restore. Is there an easier way to get them all restored? I branched code in TFS from another developer and have no knowledge of what libraries could be needed. i am also new to working with web applications. any advice is welcome. Thanks!

    Reply
    1. Thomas Eaves

      Yes, I ran into this issue, as well (the selecting a missing menu option issue). I am using VS 2010 and was able to then go to “Manage NuGet Packages for Solution” and go to “Updates”. This then enabled me to force NuGet to Update each of the dependencies and solved the majority of my errors related to “Missing… etc.”

      Reply
  5. TomK

    > Now if you again right-click on the Solution from Visual Studio’s Solution Explorer menu, you will notice that the [A] “Enable NuGet Package Restore” menu is gone,
    leaving only the [B] “Manage NuGet Packages for Solution” option.
    Select the [A] “Enable NuGet Package Restore” menu to bring up the NuGet management dialog.

    Could you walk me through once more how I select the option that is gone?

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s