One of the things I noticed recently as a part of my demo programming is that when trying to access localhost to instantiate your local sharepoint site is not always guaranteed to work. Of course in real scenarios you`re recommended to use SPContext to instantiate your objects but in some cases and definitely in demo scenario – it`s common to type
new SPSite(`http://localhost`);
As I was making changes to sharepoint alternative access mapping in Central Administration, I deleted localhost from the list of my mapping; not a big deal, however, this directly resulted in my localhost not being recongized when making references to. As soon as I placed it back in to the mapping – my objects were instantiated properly.
Below is my demo setup:
In here, the internal URL will translate into the actual underlying lower level network communication layers once you make a reference to them.