In many cases you may have multiple web applications running on the same machine simultaneously. When using attach to process debugging approach, you need to know the exact process id of the application you are debugging. This command will do this work for you:
This error happens often on the development Sharepoint 2010 machine after upgrade from sharepoint 2007 when trying to deploy solution from Visual Studio. In my case, the problem was related to incorrect upgrade of sharepoint publishing feature. It was upgraded with the feature activated. To correct the issue, it was sufficient to deactivate the publishing feature and reactivate it.