question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Access to the path is denied - MacOS 11 - Net6.0

See original GitHub issue

Describe 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 and pwsh 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:open
  • Created 2 years ago
  • Reactions:5
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
JamieHWKcommented, Dec 9, 2021

Hi @baronfel,

Thanks for the suggestion, I performed the following steps:

  • dotnet clean
  • Added <UseAppHost>False</UseAppHost> to the csproj file
  • dotnet build
  • Built successfully
  • Removed/commented out UseAppHost
  • Build failed with same result

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:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>

    <IsPackable>false</IsPackable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="FluentAssertions" Version="6.2.0" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
    <PackageReference Include="Selenium.WebDriver" Version="4.0.1" />
    <PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="95.0.4638.6900" />
    <PackageReference Include="SpecFlow" Version="3.9.40" />
    <PackageReference Include="SpecFlow.NUnit" Version="3.9.40" />
    <PackageReference Include="SpecFlow.NUnit.Runners" Version="3.9.40" />
  </ItemGroup>

</Project>

When this runs, I get essentially the same exception however it’s nothing to do with the AppHost file. Exception is listed below:

jamie.hopper | ~/ProjectPath/ProjectName 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.
  SpecFlowFeatureFiles: Features/Example.feature
-> Using default config
  SpecFlowGeneratedFiles: Features/Example.feature.cs
  ProjectName -> /Users/jamie.hopper/ProjectPath/ProjectName/bin/Debug/net5.0/ProjectName.dll
/Users/jamie.hopper/.nuget/packages/selenium.webdriver.chromedriver/95.0.4638.6900/build/Selenium.WebDriver.ChromeDriver.targets(89,5): error MSB3021: Unable to copy file "/Users/jamie.hopper/.nuget/packages/selenium.webdriver.chromedriver/95.0.4638.6900/build/../driver/mac64/chromedriver" to "/Users/jamie.hopper/ProjectPath/ProjectName/bin/Debug/net5.0/chromedriver". Access to the path is denied. [/Users/jamie.hopper/ProjectPath/ProjectName/ProjectName.csproj]

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?

0reactions
jjxtracommented, Apr 6, 2023

Same error here. Gave up on vs mac and just continued to use windows vs…

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found