You may see error like
Unhandled Exception: System.IO.FileNotFoundException: The Web application at http://sp2010:12523 could not be found.
Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.
while debugging the code.
When you create a new application, it defaults to x86. However SharePoint 2010 is a 64 bit application.
To resolve the issue, View your project properties, go to the Build tab and change the platform target to x64. Run your application again and everything should work as expected now.