Forum Discussion
System.UnauthorizedAccessException: Access to the Path is Denied During Azure Pipeline Execution
These steps should help prevent the access issue from recurring.
1. Why does this error only occur during the first execution of the pipeline, and why is it resolved upon retriggering?
The error happens on the first run because the DLL might be locked by another process. By the time you retrigger the pipeline, that process has released the lock, allowing the second attempt to succeed.
2. Could this be related to file lock management by the self-hosted agent, or interference from explorer.exe or other processes?
Yes, it’s probably due to file locks. The self-hosted agent may be trying to access the DLL while another application is still using it. Background processes, including explorer.exe, could also interfere.
3. What would be the best approach to avoid this issue altogether, without relying on restarting explorer.exe?
To avoid this issue:
Add Retry Logic: Implement retries in your pipeline if it encounters a lock.
Pre-Execution Check: Check if the DLL is locked before running tasks. If it is, wait a moment and try again.
Optimize Agent Setup: Ensure the agent runs under a dedicated user with proper permissions.
Identify Locking Processes: Use tools like Process Explorer to find what’s locking the DLL.
Reference URL:
- https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/v2-windows?view=azure-devops
- https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea#file-locking