Could not load file or assembly, Access is denied.

I have an asp.net application that uses an assembly NHibernate.dll, plus a bunch of other assemblies that this first one is dependent on. The application is getting an error periodically "Could not load file assembly... Access is denied". Once the error
occurs it will not go away. It doesn't always occur for the same file - sometimes it occurs for files that NHibernate.dll is depedent on. Does anyone have ideas how to fix this?

This app runs fine on my local. At first, it runs fine on a staging server too. But then, on the staging server, at some point I get an exception:

Could not load file or assembly 'NHibernate, Version=1.0.3.0, Culture=neutral, PublicKeyToken=3a53e011584a29df' or one of its dependencies. Access is denied.

Based on where the error occurs in the call stack, this seems to be occuring when a new app domain is created.

Looking at the assembly load trace I see:

Assembly Load Trace: The following information can be helpful to determine why the assembly
'NHibernate, Version=1.0.3.0, Culture=neutral, PublicKeyToken=3a53e011584a29df' could not be loaded.

One thing that puzzles me a lot is why the worker process is not trying to access the copy of the assembly in the "/Temporary ASP.NET Files" folder. Shouldn't it be using this "Shadow Copy" of the file? Or is it attempting this access, failing,
and then continuing with the other locations?

When I run the app locally, I see that the file in the bin directory is accessed (I see this using the ProcessMon tool), and not the copy in the /Temporary ASP.NET Files folder. Is this a problem? Could this be some issue with multiple worker processes
trying to access the same file?

When I tried running ProcessMon on the stagging server where the error occurs, once the error is occuring, using ProcessMon I don't see any attempt to access NHibernate.dll anywhere. This is puzzling too - I get this error above but ProcessMon doesn't see
the failed access (unless I have my filter setup wrong, which is quite possible...)

Re: Could not load file or assembly, Access is denied.

For an "Access is denied" message (for hresult E_ACCESSDENIED, 0x80070005):
Run tlist -m on the file to see if another process has the file locked and without share-read access. If not, check the ACLs for the file and its dependencies (especially if you're using impersonation).

I ran tlist -m previously and it shows that the worker process is accessing the file, as I mention in my post.

So my question is, is it normal that the web application is hitting the file in the \bin directory and not the file in the temporary internet folder (shadow copy folder)?

Re: Could not load file or assembly, Access is denied.

Check your Framework... I had the same problem with Framework2.0 SP1. My components are developed in Framework2.0 then i updated machine with SP1, i got the same error for all the components.
Check your Framework in IIS.
Clear all the temp. files, sometimes two version of same DLL cause this kind of issues.