Could not load file or assembly or one of its dependencies. Access is denied. The issue is random, but after it happens once, it continues
Asked Answered
E

21

90

I have found plenty of information out there about this error: 'ERROR: Could not load file or assembly '*.dll' or one of its dependencies. Access is denied.’ But i haven't found answer specific to my scenario. My site is deploy on 6 different production servers, only on one server i am facing this issue. The issue is random, but after it happens once, it continues until the site is recompile by done a small modification in web.config file(i know trick, after modification in web.config recompile the web application) and site on that server start working. Yesterday, issue was reproducing after one month period of working. We can't afford this issue on production.
Issue detail:

Server Error in '/' Application. ____________________________________ Could not load file or assembly 'MainCore.DbImpl, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. Access is denied. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileLoadException: Could not load file or assembly 'MainCore.DbImpl, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. Access is denied.

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.

Assembly Load Trace: The following information can be helpful to determine why the assembly 'MainCore.DbImpl, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' could not be loaded.

WRN: Assembly binding logging is turned OFF. To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1. Note: There is some performance penalty associated with assembly bind failure logging. To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

Stack Trace:

[FileLoadException: Could not load file or assembly 'MainCore.DbImpl, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. Access is denied.] ...DbImpl.Event.TTCEventController.GetEventFields(Int32 eventId) +0 WebSuite.SportChannel.ModelImpl.TTCModelController.AddEventFieldList(XmlElement eventNode, ITTCEventController ctrl, Int32 eventId, PlayerType stupidType) in ...root\SportChannel\ModelImpl\Ttc\TTCModelController.cs:171 ...ModelImpl.TTCModelController.GetLatestFourTourSchedulesXml() in ...root\SportChannel\ModelImpl\Ttc\TTCModelController.cs:283 ...WebRoot.UserControls.HeadlinesTab.Page_Load(Object sender, EventArgs e) +491 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +42 System.EventHandler.Invoke(Object sender, EventArgs e) +0 System.Web.UI.Control.OnLoad(EventArgs e) +132 System.Web.UI.Control.LoadRecursive() +66 System.Web.UI.Control.LoadRecursive() +191 System.Web.UI.Control.LoadRecursive() +191 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2428
____________________________________

Version Information: Microsoft .NET Framework Version:2.0.50727.5446; ASP.NET Version:2.0.50727.5420

Engdahl answered 19/6, 2012 at 7:23 Comment(8)
Was this issue caused by uploading a new version of the dll?Freeloader
No change, same old dll on all servers, nothing changeEngdahl
Same old version of MainCore.DbImpl.dll on all servers, didn't upload or change anything.Engdahl
Try cleaning/deleting Temporary ASP.Net files next time this happens, bcoz for cleaning them you might need to restart the IIS.Reamy
how i avoid occurring this issue next time on this server??Engdahl
Can we determine the reason for this crash??? Help!!!Engdahl
sometime it does happen due to rebuild your solution.to avoid this error replace your all backup bin dll files that you previously have before rebuild solution.Opisthognathous
Same issues witg C1.Web.Wijmo.Controls.4. Any solutions ?Rhyner
E
27

My solution is as follows:

I didn't find a root folder under C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files.

Google told me that it might be a permission issue against current user, then I found I have a current Identity: IIS APPPOOL in the malfunctioning server where the rest of the server has Current Identity: NT AUTHORITY\NETWORK SERVICE.

Then I changed Current Identity from IIS APPPOOL to NT AUTHORITY\NETWORK SERVICE.

From here, I found that resetting the web app rebuilds the temporary ASP.NET cache, solving the issue.

Engdahl answered 20/6, 2012 at 7:42 Comment(2)
Any solution for the same issue with C1.Web.Wijmo.Controls.4 assembly ? getting Could not load file or assembly 'C1.Web.Wijmo.Controls.4, Version=4.0.20163.250, Culture=neutral, PublicKeyToken=9b75583953471eea' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)Rhyner
@Bhat: Yours is an entirely different problem. Just compare the error messages.Stenophyllous
B
57

For my scenario, I found that there was a identity node in the web.config file.

<identity impersonate="true" userName="blah" password="blah">

When I removed the userName and password parameters from node, it started working.

Another option might be that you need to make sure that the specified userName has access to work with those "Temporary ASP.NET Files" folders found in the various C:\Windows\Microsoft.NET\Framework{version} folders.

Hoping this helps someone else out!

Burdelle answered 12/11, 2013 at 16:48 Comment(4)
For me, locally running the solution means removing the identity node completely from web.config, but deploying it to production servers requires the impersonation and so the identity node must be added. See my answer here for more detailIndolent
I added the impersonating user to the local group called IIS_IUSRS, instead of trying to find out exactly which of the "various framework folders" to use.Sussex
Don't forget that impersonation could be done via code (without web.config), in my case user (anonymous logon) has been saved in Chrome browser. Had to restart Chrome and revisit website to enter my user credentials.Faris
@AndreasJansson's method of adding the impersonated user to IIS_IUSRS worked for me. I would suggest trying this first, if you're impersonating a user. It takes only a couple of minutes to do so if it doesn't work you haven't wasted much time. No need to restart your machine or your app pool, you can test your web app straight away.Parachronism
M
45

Had the same issue, fixed with setting the parameter "Enable 32-bit applications" to "true" (in advanced settings of iis application pool).

Microclimatology answered 7/8, 2014 at 11:3 Comment(6)
This answer along with Love Chopra's solution worked for me.Boatright
Great answer! If, like me, you are trying to publish to Azure and get the same error, Go to your app on the Azure portal, Go to Application settings and Select the "64-bit" option for the "Platform" setting.Barbabas
@Barbabas Why 64-bit? Why does that help?Sensuality
I got the same error, I had to turn "Enable 32-bit applications" to "false", as my application is 64bitPuzzlement
It worked for me <3Globetrotter
Ding Ding Ding. We have a winner. Could not run exe on NAS without this.Cambist
E
27

My solution is as follows:

I didn't find a root folder under C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files.

Google told me that it might be a permission issue against current user, then I found I have a current Identity: IIS APPPOOL in the malfunctioning server where the rest of the server has Current Identity: NT AUTHORITY\NETWORK SERVICE.

Then I changed Current Identity from IIS APPPOOL to NT AUTHORITY\NETWORK SERVICE.

From here, I found that resetting the web app rebuilds the temporary ASP.NET cache, solving the issue.

Engdahl answered 20/6, 2012 at 7:42 Comment(2)
Any solution for the same issue with C1.Web.Wijmo.Controls.4 assembly ? getting Could not load file or assembly 'C1.Web.Wijmo.Controls.4, Version=4.0.20163.250, Culture=neutral, PublicKeyToken=9b75583953471eea' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)Rhyner
@Bhat: Yours is an entirely different problem. Just compare the error messages.Stenophyllous
U
27

To anyone else who tried most of the solutions but still having problems.

My solution is different from the others, which is located at the end of this post, but before you try it make sure you have exhausted the following lists. To be sure, I have tried all of them but to no avail.

  1. Recompile and redeploy from scratch, don't update the existing app. SO Answer

  2. Grant IIS_IUSRS full access to the directory "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files"

Keep in mind the framework version you are using. If your app is using impersonation, use that identity instead of IIS_IUSRS

  1. Delete all contents of the directory "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files".

Keep in mind the framework version you are using

  1. Change the identity of the AppPool that your app is using, from ApplicatonPoolIdentity to NetworkService.

IIS > Application Pools > Select current app pool > Advance Settings > Identity.

SO Answer (please restore to default if it doesn't work)

  1. Verify IIS Version and AppPool .NET version compatibility with your app. Highly applicable to first time deployments. SO Answer

  2. Verify impersonation configuration if applicable. SO Answer

My Solution:

I found out that certain anti-virus softwares are actively blocking compilations of DLLs within the directory "Temporary ASP.NET Files", mine was McAfee, the IT people failed to notify me of the installation.

As per advice by both McAfee experts and Microsoft, you need to exclude the directory "Temporary ASP.NET Files" in the real time scanning.

Sources:

Don't disable the Anti-Virus because it is only doing its job. Don't manually copy missing DLL files in the directory \Temporary ASP.NET Files{project name} because thats duct taping.

Unhand answered 8/5, 2014 at 7:3 Comment(5)
Clearing temporary ASP.Net files worked for me even though the error only referenced (repeatedly) my local bin. Very confusing.Verbena
Thank you very much... I've been fighting against this annoying error for almost two weeks. When I disabled my antivirus (BitDefender Free Antivirus), everything works fine again.Laurentia
every 6 months or so I have a mis-behaving dev deployment that sends me back to this same SO answer - great write-up @Yorro!. Again, even though it truly ended up being that my impersonation user needed access to the Temporary ASP.NET Files dir, I seemed to not get to the error until I deleted my application from IIS (not the underlying files) and re-added the application back into IIS.Indolent
In my case I discovered McAfee was blocking access for my .Net application's dlls as seen in McAfee's logs. I had to go into McAfee's "Access Protection" and change the "Anti-spyware Maximum Protection". Then remove the Block check for the item called "Prevent all programs from running files from the Temp folder". This can be configured instead of disabled which is better. Look in the AccessProctectionLog.txt to see the messages if it's blocking or reporting. Location of log is on the Reports tab page.Groggy
I get error using IIS Expresss in development environment. The same issue about AppPools.Afterburner
A
7

If you are using impersonation, be sure to give permissions, including write and modify permission to the relevant user account on the following folder:

C:\Users\[username]\AppData\Local\Temp\Temporary ASP.NET Files

I was missing the modify permission, which was why just adding the default permissions wasn't working for me.

Apolitical answered 4/11, 2014 at 22:41 Comment(2)
I followed only these steps, instead of the more complex ones in the selected answer - and this alone solved it.Ruddie
This worked for me too. I used Sysinternal's Process Monitor from Technet to find the blocked folder, which was the "Temporary ASP.NET Files" folder mentioned. In Process Monitor, you turn everything off except the "File System Activity" button and then can search for "ACCESS DENIED".Sanchez
Y
7

Go to IIS -> Application Pool -> Advance Settings -> Enable 32-bit Applications

Yap answered 16/11, 2017 at 4:34 Comment(2)
You beauty!! Saved me a worldddd of problemsSolicitor
Note: This setting is necassary if COM (or any other 32-bit library) is used. In my case COM was the deal.Corruptible
C
4

If you still facing the issue try this:

Open your IIS Manager -> Application Pools -> select your app pool -> Advance Setting -> Under 'Process Model' set 'Load User Profile' setting as True

enter image description here

Charmeuse answered 5/2, 2016 at 10:25 Comment(1)
This answer along with Fragment's solution worked for me.Boatright
B
4

I believe I wasted like 1 day on researching it and this what I have come out with.

You need to add the Impersonating user to the Debug folder of your Solution as the Framework will try to access the DLL from this location and place it in Temporary Asp.Net Folder.

So basically follow these 2 steps

  1. Give permission to Temporary Asp.Net Folder under C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files and make sure the user you are adding here is the same you are using while Impersonating.

  2. Add the Impersonating user to the Debug folder of your Solution YourSolutionPath .. \bin\Debug

This should work

Bipolar answered 18/10, 2016 at 16:11 Comment(0)
P
4

For me, the following hack worked; Go to IIS -> Application Pools -> Advance Settings -> Process Model -> Identity Changed from Built-in Account (ApplicationPoolIdentity) to Custom Account (My Domain User)

Perfectible answered 3/9, 2018 at 11:43 Comment(0)
H
3

I had the same issue, fixed by rebuild and redeploy ALL Dependents Dll files

Horten answered 1/9, 2015 at 8:15 Comment(0)
T
3

In my case it was due to the Access Protection feature of my anti-virus (McAfee). It was obviously blocking access to this file, as of such the error.

I disabled it and the solution ran. You might want to check any utility application you might have running that could be affecting access to some files.

Trinary answered 4/11, 2015 at 18:53 Comment(1)
I had to go into McAfee's "Access Protection" and change the "Anti-spyware Maximum Protection". Then remove the Block check for the item called "Prevent all programs from running files from the Temp folder". This can be configured instead of disabled which is better.Groggy
C
2

Check the IIS settings. I use IIS 7.5 with 32 or 64 bit compilation within the .NET framework. If you have an app that uses 32-bit mode, make sure to enable the App Pool to be able to use 32-bit instruction. Otherwise, nothing seems to work no matter how much you set the security or strong sign the DLL.

Cozenage answered 22/10, 2015 at 22:53 Comment(0)
B
2

I am setting-up environment on new server. My web.config got identity node like below.When I faced with "Could not load file or assembly or one of its dependencies. Access is denied. The issue is random, but after it happens once, it continues"

Added ccs\HJKWeb as users list of my new server.

  <authentication mode="Windows" />
        <identity impersonate="true" password="******" userName="ccs\HJKWeb" />
Bashaw answered 31/5, 2018 at 13:32 Comment(0)
M
1

I got this error running from VS. Turned out I'd opened a solution without running Visual Studio as admin. Closing Visual studio down and running it again as admin then rebuilding solved this for me.

Hope that helps someone.

Multipartite answered 24/4, 2015 at 8:59 Comment(1)
Exactly! I was having the same problem, and this solution works for me :) To pinpoint, the cause is that a user as specified in identity tag, has no access to a specific dependency in the local files. So running it as administrator gives it a go.Randolf
P
1

I was not using impersonation in my case. My solution was to give full access to my project directory for the user group "IIS_IUSRS".

Parttime answered 4/6, 2015 at 14:16 Comment(0)
I
1
 Go to run  : ctrl + R
 Type : %temp%

delete All files & folders

 Rebuild Project.
 done!
Incision answered 1/7, 2016 at 14:15 Comment(0)
T
1

I ran into this problem and it turned out that a referenced package/assembly was being encrypted by Windows. This happened because my company implemented a policy to require the My Documents folder to be encrypted and my Visual Studio solutions happened to be under that directory.

I could manually go into the file/directory properties in Windows Explorer and disable encryption. But in my case this was a temporary solution since the network policy would eventually change it back. I wound up moving my VS solution to another un-encrypted location.

Tonguetied answered 28/10, 2016 at 2:18 Comment(0)
G
1

In my case, I had copied a service from one server to another without performing a proper deployment from Visual Studio. Long story.

Anyway, I had setup all of the appropriate NTFS permissions and whatnot, but it still couldn't load the main DLL for the service.

I fixed it by renaming the corresponding service.pdb file to something else.

For example here's my bin folder: \bin\ service.dll service.dll.config service.pdb I renamed service.pdb to zzservice.pdb, and then the service.dll loaded fine.

Gabey answered 7/9, 2017 at 13:5 Comment(1)
It may have fixed your problem but it doesn't explain the causeTideway
T
1

If you get the DLL could not be found instead of access denied, make sure you have the appropriate VC++ Redistributable installed.

Tenrec answered 19/7, 2018 at 0:22 Comment(0)
M
0

In my case, I was using simple impersonation and the impersonation user had trouble accessing one of the project assemblies. My solution:

  1. Look for the message of the inner exception to identify the problematic assembly.
  2. Modify the security properties of the assembly file.

    a) Add the user account you're using for impersonation to the Group and user names.

    b) Give that user account full access to the assembly file.

Malynda answered 24/8, 2016 at 20:23 Comment(0)
H
0

In my case Users with read access had to be added to the folder permissions. I removed them by accident. COMPUTER\Users

Hoodmanblind answered 24/1, 2022 at 13:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.