This is a common error we are came across most of the time.
When you are running inside the SharePoint common resolutions are
- Running the web application in 64-bit mode.
- Changing to target framework to 3.0 instead of 4.0
- Adding app pool identity user to WSS_ADMIN_WPG
- Adding app pool identity user to Administrator group
But when you are creating a Web Service (WCF) or a Other Web Project which is ruining inside the SharePoint server but not inside the SharePoint You need to Change the AppPool Account to; which SharePoint is running.