This error sometimes comes during publishing website that implements impersonation. When impersonation setting is made in the web.config file and the impersonate user dose not have access permission on the temp directory, this error likely to come. Although I don’t understand why impersonate user needs access permission on temp directory because during publishing website is precompiled and copied in the given location.
Anyways the solution that worked for me is that I commented the impersonation setting in the web.config file and then published it after publishing succeed I uncommented the settings from the web.config file in the published folder.