Stian Hanger
Stian Hanger

Reputation: 31

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

I'm getting an EventLog error that's unknown to me when running a .NET webapp.

The app basically reads from a database, and then from the disk (reads file-sizes and then writes back to the database).

I've got the app up and running with no problems on my workstation (IISExpress) and our other server (Windows 2008 with IIS7)

But when I run it on our 2003 R2 server with IIS6 I get some odd behaviour. The IIS app starts and reports nothing wrong, but when I try to access the webpage I get a "Server Application Unavailable" and the EventLog on the server gives me this dump:

Event Type: Error
Event Source:   ASP.NET 4.0.30319.0
Event Category: None
Event ID:   1325
Date:       24.05.2011
Time:       13:29:11
User:       N/A
Description:
Failed to initialize the AppDomain:/LM/W3SVC/1309226359/Root

Exception: System.IO.FileLoadException

Message: Could not load file or assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Access is denied.

StackTrace:    at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Activator.CreateInstance(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(String assemblyName, String typeName)
at System.AppDomain.CreateInstance(String assemblyName, String typeName)
at System.AppDomain.InternalCreateInstanceWithNoSecurity(String assemblyName, String typeName)
at System.AppDomain.InternalCreateInstanceWithNoSecurity(String assemblyName, String typeName)
at System.Activator.CreateInstance(AppDomain domain, String assemblyName, String typeName)
at System.Web.Hosting.ApplicationManager.CreateAppDomainWithHostingEnvironment(String appId, IApplicationHost appHost, HostingEnvironmentParameters hostingParameters)
at System.Web.Hosting.ApplicationManager.CreateAppDomainWithHostingEnvironmentAndReportErrors(String appId, IApplicationHost appHost, HostingEnvironmentParameters hostingParameters)

The app continues to run in IIS. This IIS also hosts a whole bunch of other sites without any problems. And yes, the app is set to run on .NET 4, and the server hosts other .NET 4 apps without any problems as well.

From what I can tell, it can't load the System.Web assembly, but I'm not sure how that's even possible...

Here is the web.config for the app:

<?xml version="1.0"?>
<configuration>
    <system.web>
        <globalization culture="nb-NO"/>
        <compilation debug="true" targetFramework="4.0">
            <assemblies>
                <add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
            </assemblies>
            </compilation>
        <customErrors mode="Off"></customErrors>
        <xhtmlConformance mode="Strict"/>
        <httpRuntime requestValidationMode="2.0"/>
    </system.web>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"></modules>
    </system.webServer>
</configuration>

Upvotes: 3

Views: 4895

Answers (2)

Caskman
Caskman

Reputation: 359

Lachlan Roche's answer worked for me. Specifically I granted Full Control to my web application folder to LOCAL_MACHINE\Users and LOCAL_MACHINE\IIS_IUSRS where LOCAL_MACHINE was my local machine's domain. I didn't check whether or not both groups needed full access so you probably don't need to give access to both.

My system is Windows 7 Enterprise with IIS 7.5.7600.16385 and Visual Studio 12

Upvotes: 0

Lachlan Roche
Lachlan Roche

Reputation: 25946

This can be caused by insufficient filesystem permissions in your web application folder.

I resolved the same symptoms by giving the ASPNET and Network Service accounts Read & Execute and List Folder Contents permissions to the web root and all children.

Upvotes: 2

Related Questions