A suite of integrated tools for creating, running, and managing tests to ensure code quality and reliability.
Thanks for reaching out. This is a classic error which usually means the C# compiler/MSBuild cannot create the temporary output DLL because the temp/output path is invalid or inaccessible (missing folder, wrong environment variable, network path, permissions, disk full or AV lock).
Here are some troubleshooting steps and fixes:-
Follow these in order-each step includes commands you can copy/paste.
- Check the actual TEMP/TMP values and folder existence
- Open an elevated Command Prompt ( or PowerShell) and run:
echo %TEMP% echo %TMP% dir "%TEMP%" dir "%TMP%" - In PowerShell:
$env: TEMP $env: TMP Test-Path $env:TEMP
- Open an elevated Command Prompt ( or PowerShell) and run:
- If the folder doesn't exists, create it:
- Example: Set to a local folder C:\Temp and create it if missing:
mkdir C:\Temp
- Example: Set to a local folder C:\Temp and create it if missing:
- Temporarily point TEMP/TMP to a known good local folder (test only)
- Set System TEMP/TMP to C:\Temp (requires admin). After this you must sign out/ sign in (or restart Visual Studio /the service) to pick up the change.
setx /M TEMP "C:\Temp" setx /M TMP "C:\Temp" - Then restart Visual Studio / IIS / the build agent and try the build again.
- Set System TEMP/TMP to C:\Temp (requires admin). After this you must sign out/ sign in (or restart Visual Studio /the service) to pick up the change.
- Check permissions on the temp folder
- Ensure the account performing the build has write permissions. For local developer builds this your user account; for IIS/ ASP.NET compilation it may be IIS APPPOOl \ <apppool> or NETWORK SERVICE.
- Quick way to grant your account access:
# replace " YourDomain/ YourUser" with your user if needed icacls "C:\Temp" /grant "%USERNAME%:(OI)(CI)F" /T - for server/CI scenarios, grant the service account (e.g., NETWORK SERVICE or the build agent user) the needed rights instead of granting everyone.
- Clear temp files
- Delete the leftover temporary files which may be corrupt:
rd /s /q "%TEMP%" mkdir "%TEMP%" - (Only remove files from user temp folder; do not delete system critical folders. if in doubt, reboot to clear locks.)
- Delete the leftover temporary files which may be corrupt:
- Check antivirus / endpoint protection
- Temporarily disable AV (or better: create an exclusion for the temp folder or the Visual Studio/MSBuild process) and retry the build. Some AVs block creation of DLLS in temp folders.
- If using a network drive or redirected TEMP
- Move Temp/TMP to a local disk. Compilation generally requires a local folder. Network - mapped drives or disconnected user profiles frequently cause this error.
- If building on a build server / Azure DevOps / IIS
- Verify the agent/service account's environment variables and workspace. for Windows services, check the service account's profile and temp location.
- Ensure the build agent is running under an account with valid local profile.
- Run Visual Studio as Administrator (test only)
- Right click Visual Studio-> Run as administrator and try a clean + rebuild. if that fixes it, it's permission related and you should properly fix permissions rather than always running admin.
- Check disk space & Path length
- Ensure target disk has space: Wmic logicaldisk get size, freespace, caption
- Long paths sometimes cause issues, Try to shorten project paths.
- If you still see the issue: capture build log & exact error
- from developer command prompt:
msbuild YourSolution.slm /t:Rebuild /v:diag > buildlog.txt - Inspect buildlog.txt for the real folder MSBuild tried to use and any inner exception text. Share that to get more details.
- from developer command prompt:
Please let us know if you require any further assistance we’re happy to help. If you found this information useful, kindly mark this as "Accept Answer".