The file 'filename' cannot be copied to the run directory. <reason>
This error is displayed when:
- A reference that has the CopyLocal property (see the Properties window when the reference is selected in Solution Explorer) set to true could not be copied to the directory from which the project is being run.
- A dependency of a reference with a CopyLocal property set to true could not be copied to the directory from which the project is being run.
- Any other file that needed to be copied locally cannot be copied to the directory from which the project is being run.
Most commonly, the reason cited at the end of the error message will report that the file is in use by another process. It is likely that the file is locked by something else within Visual Studio.
There may be a problem associated with building projects into the same output directory. In this case, build the two projects to different directories. When building into different directories, the project system copies all dependent assemblies into a project's output directory.
Adding the output of any project you are working on as a Toolbox item will cause the managed designers to lock the reference.
The project system will not be able to update the output directory if the output is currently running.
To correct this error
- Check your computer's available disk space
- Check whether you are hitting the MAX_PATH limit imposed by the file system
The situation will not prevent the project from building. However, it may prevent the project from running correctly, because this warning indicates that a private copy of a referenced assembly could not be updated correctly. Although the project may appear to run, you may get a type load exceptions or other unexpected behavior when executing certain code paths.