'System.UnauthorizedAccessException in mscorlib.dll
I was developing an ASP.NET application. Then I did not test the application in the debugger of Visual Studio, but transferred it via File Deploy to another server. The application works there.
After I shut down the computer, I wanted to develop again. Since then, I can no longer launch my application in the Visual Studio debugger / IIS. The following error message always appears:
Exception raised: "System.UnauthorizedAccessException" in mscorlib.dll ("The access to the path" C: \ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ Temporary ASP.NET Files \ AspCheck_b8e5127411412.tmp "was denied." )
The mentioned path does not contain any file.
Why are there no more assemblies any more? Is this a special setting that was made when I was publishing to another destination?
I would appreciate your help!
Solution 1:[1]
The Temporary ASP.NET Files it is where .NET dynamically store your compiled site. For example every *.cs file in App_Code folder will be built into a i23y4ui.dll and moved to a 247ksdfklj folder. Those names are formed dynamically as well.
What I would recommend is that
Option #1:
On your DEV machine you
go to this folder:
C: \Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\
Stop IIS or IIS Express
and delete everything inside the folder. This will force your application to recompile entirely.
Option #2:
Is to start your Visual Studio as administrator. Sometimes of the windows options are kind of locked for some users and this may also cause this error. This happens more often when the site is hosted in IIS.
Option #3:
Create a folder with FULL access to "EVERYONE" and set it in your compile element in the web.config
<system.web>
<compilation tempDirectory="C:\MyCompilationTest\temporary_asp_net_files\test1" />
</system.web>
Solution 2:[2]
For others facing similar issue, do note this can also be caused by a bug in your own code. In my case, I had the wrong model assigned to the view in the MVC controller.
In controller:
MyWrongModel model = new MyWrongModel();
return View(model);
In View:
@model CorrectModel;
Solution 3:[3]
As Jack said, you can have this issue when you have a bug in your code - even if build is successful. I ran into this with a duplicate rewrite rule name, so if you've modified your .config file[s] check there!
Solution 4:[4]
I had this stupid problem twice and it's always for installing Microsoft Visual x86 elements, or having duplicate installs of the same year's edition. Removing them seems to do the trick at the two times...
Solution 5:[5]
If it still can help anyone, it just happened to me.
Solution:
From the project directory, deleting the .suo file in folder .vs/config/[projectName]/v16
(for Visual Studio 2019) and restarting Visual Studio made the error disappear.
Hope it helps.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Community |
Solution 2 | Jack |
Solution 3 | Ken Hanscom |
Solution 4 | Dharman |
Solution 5 |