Access to the path is denied - MacOS 11 - Net6.0
See original GitHub issueDescribe the bug
When trying to perform a build of a dotnet project, it fails with Access to path is denied exception. The build should succeed.
File permissions look correct and the copy step can be performed manually successfully.
On rerun of the build command, the build succeeds. It should work first time. In some situations in other more complex repos, it fails consistently. The simple scenario is detailed below.
To Reproduce
jamie.hopper@<machineID> Misc % dotnet --info
.NET SDK (reflecting any global.json):
Version: 6.0.100
Commit: 9e8b04bbff
Runtime Environment:
OS Name: Mac OS X
OS Version: 11.6
OS Platform: Darwin
RID: osx.11.0-x64
Base Path: /usr/local/share/dotnet/sdk/6.0.100/
Host (useful for support):
Version: 6.0.0
Commit: 4822e3c3aa
.NET SDKs installed:
5.0.403 [/usr/local/share/dotnet/sdk]
6.0.100 [/usr/local/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 5.0.12 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 5.0.12 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download
jamie.hopper@<machineID> Misc % dotnet new console -n AccessDeniedDemo
The template "Console App" was created successfully.
Processing post-creation actions...
Running 'dotnet restore' on /Users/jamie.hopper/Src/Misc/AccessDeniedDemo/AccessDeniedDemo.csproj...
Determining projects to restore...
Restored /Users/jamie.hopper/Src/Misc/AccessDeniedDemo/AccessDeniedDemo.csproj (in 81 ms).
Restore succeeded.
jamie.hopper@<machineID> Misc % cd AccessDeniedDemo
jamie.hopper@<machineID> AccessDeniedDemo % dotnet build
Microsoft (R) Build Engine version 17.0.0+c9eb9dd64 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
All projects are up-to-date for restore.
/usr/local/share/dotnet/sdk/6.0.100/Microsoft.Common.CurrentVersion.targets(5100,5): error MSB3021: Unable to copy file "/Users/jamie.hopper/Src/Misc/AccessDeniedDemo/obj/Debug/net6.0/apphost" to "bin/Debug/net6.0/AccessDeniedDemo". Access to the path is denied. [/Users/jamie.hopper/Src/Misc/AccessDeniedDemo/AccessDeniedDemo.csproj]
Build FAILED.
/usr/local/share/dotnet/sdk/6.0.100/Microsoft.Common.CurrentVersion.targets(5100,5): error MSB3021: Unable to copy file "/Users/jamie.hopper/Src/Misc/AccessDeniedDemo/obj/Debug/net6.0/apphost" to "bin/Debug/net6.0/AccessDeniedDemo". Access to the path is denied. [/Users/jamie.hopper/Src/Misc/AccessDeniedDemo/AccessDeniedDemo.csproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:02.83
And the output from the file referenced in the exception:
jamie.hopper@<machineID> AccessDeniedDemo % ls -lh obj/Debug/net6.0
total 504
-rw-r--r-- 1 jamie.hopper staff 959B 7 Dec 10:21 AccessDeniedDemo.AssemblyInfo.cs
-rw-r--r-- 1 jamie.hopper staff 41B 7 Dec 10:21 AccessDeniedDemo.AssemblyInfoInputs.cache
-rw-r--r-- 1 jamie.hopper staff 443B 7 Dec 10:21 AccessDeniedDemo.GeneratedMSBuildEditorConfig.editorconfig
-rw-r--r-- 1 jamie.hopper staff 287B 7 Dec 10:21 AccessDeniedDemo.GlobalUsings.g.cs
-rw-r--r-- 1 jamie.hopper staff 145B 7 Dec 10:21 AccessDeniedDemo.assets.cache
-rw-r--r-- 1 jamie.hopper staff 70K 7 Dec 10:21 AccessDeniedDemo.csproj.AssemblyReference.cache
-rw-r--r-- 1 jamie.hopper staff 41B 7 Dec 10:21 AccessDeniedDemo.csproj.CoreCompileInputs.cache
-rw-r--r-- 1 jamie.hopper staff 881B 7 Dec 10:21 AccessDeniedDemo.csproj.FileListAbsolute.txt
-rw-r--r-- 1 jamie.hopper staff 4.5K 7 Dec 10:21 AccessDeniedDemo.dll
-rw-r--r-- 1 jamie.hopper staff 10K 7 Dec 10:21 AccessDeniedDemo.pdb
-rwxr-xr-x@ 1 jamie.hopper staff 129K 7 Dec 10:21 apphost
drwxr-xr-x 3 jamie.hopper staff 96B 7 Dec 10:21 ref
Exceptions (if any)
Exception below:
/usr/local/share/dotnet/sdk/6.0.100/Microsoft.Common.CurrentVersion.targets(5100,5): error MSB3021: Unable to copy file "/Users/jamie.hopper/Src/Misc/AccessDeniedDemo/obj/Debug/net6.0/apphost" to "bin/Debug/net6.0/AccessDeniedDemo". Access to the path is denied. [/Users/jamie.hopper/Src/Misc/AccessDeniedDemo/AccessDeniedDemo.csproj]
Further technical details
- See in repro steps for
dotnet info
output - Consistent behaviour across
zsh
andpwsh
cli instances and from within a terminal instance within vscode - Have attempted to uninstall and reinstall desired SDKs using dotnet-core-uninstall tool and searching for references to
dotnet
and manually removing these directories and their contents.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:10 (3 by maintainers)
Top Results From Across the Web
Access to the path is denied in Vistual Studio Code for Mac
Create this directory : /Users/ppungpong/projects/FPC_E_Working.API. and work in that directory. Seems vscode does not have write access to ...
Read more >How to solve Access to the path is denied Error in C#.NET ...
Hi Team, I have an C#.Net core 3.1 console application which is running on RedHat Linux. I have to create a file in...
Read more >Access To Path Is Denied (Permissions Error)
Resolving "Access Path is Denied" error To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties", and select ...
Read more >Visual Studio for Mac 2019 8.2 System. ...
Visual Studio for Mac 2019 8.2 System.UnauthorizedAccessException: Access to the path is deniedClosed - Duplicate0 2.
Read more >[Solved] Access to the path is denied.
Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @baronfel,
Thanks for the suggestion, I performed the following steps:
dotnet clean
<UseAppHost>False</UseAppHost>
to the csproj filedotnet build
So that does indeed resolve the issue for this example which is good. It is unfortunately not the only repo that is producing this same result. I have a more complicated one, albeit not too complicated, and the csproj is listed below:
When this runs, I get essentially the same exception however it’s nothing to do with the AppHost file. Exception is listed below:
The reason I raise this, is I am conscious that the AppHost setting may be a red herring and it’s something unrelated to that which is causing this type of failure. Doing a build on this repo with the AppHost setting set to false, unsurprisingly doesn’t effect this repo and the build still fails. Would you suggest that this isn’t an SDK issue and is something else instead?
Same error here. Gave up on vs mac and just continued to use windows vs…