Tuesday, November 10, 2009

Could not load file or assembly 'app_code'

Most (if not all) of the stuff I post on this blog is about errors I have come across that took me more than a few minutes to solve. This is another of those. A web application I installed was throwing this odd error message:

Could not load file or assembly 'app_code' or one of its dependencies. Access is denied.


The strange thing was that this was a precompiled .Net (3.5) application. It didn't need app_code, and I wasn't sure why on earth it was trying to access a folder that didn't exist. I searched web.config for references to it and found nothing. I even created the folder to see what it would do, but it didn't like that either.

This server it was installed on has been behaving badly. After some poking around, I discovered that the root folder for the website didn't have two key permissions, "ASPNET" and "Network Service". I added both with read permissions and the problem went away. Now, I don't know which one fixed it, and since I was pressed for time to bring the site up, I left both of them. In hindsight, I should have removed each of them one at a time to find which fixed the problem (or if they were both needed).

Anyway, long story short, adding those two to the security of the root folder fixed the problem. It actually complained about not needing app_code for a precompiled application, so I removed the folder I had created to find the problem and suddenly the site was working again.

1 comment:

  1. I had the same problem. I have a funky production environment, where I have to manually replace the dll's in the bin.

    I got this same message today, and after seeing your blog, checked the security settings on the dll's I replaced. Lo and behold, they were missing a bunch of permissions! I right-clicked on the bin folder, Properties-Security-Advanced, and checked the box "replace permission entries on all child objects...", hit Apply, and thankfully, the app worked.

    ReplyDelete