user42348
user42348

Reputation: 4319

Couldn't load File or Assembly

I have a web application in .Net in which I use Ajax controls in some pages. Those pages are working in localhost, but when hosted, the pages in which Ajax included shows following error.

Server Error in '/Allforkids' Application.

Security Exception

Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
   System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
   System.Security.CodeAccessPermission.Demand() +58
   System.Reflection.Assembly.VerifyCodeBaseDiscovery(String codeBase) +118
   System.Reflection.Assembly.get_CodeBase() +35
   System.Web.Handlers.ScriptResourceHandler.GetCodeBaseWithAssert(Assembly assembly) +31
   System.Web.Handlers.ScriptResourceHandler.GetLastWriteTime(Assembly assembly) +36
   System.Web.Handlers.ScriptResourceHandler.GetAssemblyInfoInternal(Assembly assembly) +61
   System.Web.Handlers.ScriptResourceHandler.GetAssemblyInfo(Assembly assembly) +62
   System.Web.Handlers.RuntimeScriptResourceHandler.System.Web.Handlers.IScriptResourceHandler.GetScriptResourceUrl(Assembly assembly, String resourceName, CultureInfo culture, Boolean zip, Boolean notifyScriptLoaded) +325
   System.Web.Handlers.ScriptResourceHandler.GetScriptResourceUrl(Assembly assembly, String resourceName, CultureInfo culture, Boolean zip, Boolean notifyScriptLoaded) +33
   System.Web.UI.ScriptManager.GetScriptResourceUrl(String resourceName, Assembly assembly) +89
   System.Web.UI.ScriptRegistrationManager.RegisterClientScriptResource(Control control, Type type, String resourceName) +111
   System.Web.UI.ScriptManager.RegisterClientScriptResource(Control control, Type type, String resourceName) +9

Version Information: Microsoft .NET Framework Version:2.0.50727.3082; ASP.NET Version:2.0.50727.3082

Can anybody give appropriate solution to get rid of this error?

Upvotes: 0

Views: 1291

Answers (3)

Radu094
Radu094

Reputation: 28414

Here is the code from the Assembly class:

 private void VerifyCodeBaseDiscovery(String codeBase)
    {                
        if ((codeBase != null) &&
            (String.Compare( codeBase, 0, s_localFilePrefix, 0, 5, true, CultureInfo.InvariantCulture) == 0)) {
            System.Security.Util.URLString urlString = new System.Security.Util.URLString( codeBase );
            new FileIOPermission( FileIOPermissionAccess.PathDiscovery, urlString.GetFileName() ).Demand();
        }
    }

The exception is thrown on the .Demand() method asking for FileIOPermissionAccess.PathDiscovery to the file containing the script.

My guess is the IIS worker process does not have READ/BROWSE access to the path containing the script.

If you are registering your own scripts to the ScriptManager, check the filepath (usual rule of thumb, the scripts should not be in a parent (eg. ..\Scripts) folder).

If this exception trows on the AJAX Extensions script resources there might be a problem with the installation of the AJAX Extensions.You need to ask your hosting provider to check it.

PS. Is there more to the stack trace? It seems odd that the first call in the stack is "RegisterClientScriptResource".

Upvotes: 0

MoSlo
MoSlo

Reputation: 2860

It could be security permissions on your folder/files. Are you writing to any files (like an Access DB)? Make sure your ASP.Net machine account (such as PCName\ASPNET) on the server has access to the folder.

Upvotes: 1

Jose Basilio
Jose Basilio

Reputation: 51468

This looks like something you need to bring up with your hosting provider. It would appear from the error that a configuration setting in the hosting server prohibits access to local files.

You could try adding this to your web.config:

<system.web>
  ...
  <trust level="Medium" originUrl="" />
  ...
</system.web>

But, if the hosting provider has a setting in the machine.config that supersedes this, it will not make a difference. Here more information on that.

Upvotes: 1

Related Questions