The file ‘…’ cannot be copied to the run directory. The process cannot access the file because it is being used by another process.

I’ve been working on a BizTalk Server 2004 project that had (not anymore) between 6 or 8 visual studio solutions each one with a BizTalk Project inside. After a few minutes swapping from a solution to another, I decided to add all the project in a single solution.

I notice that all the solution are configured to build the assemblies to a common reference folder shared by all projects:

Visual studio 2003 build options

And the other project is referring to the assemblies from that folder.

However, when trying to compile the project I was getting the following error:

The file ‘MyDLLProject.dll’ cannot be copied to the run directory. The process cannot access the file because it is being used by another process.

But when I open that project isolated from the other projects I could successfully compile.

Cause

The cause is easy… the Visual Studio has a lock on the file.

Note: That this lock could be from the Visual Studio instance that you are working on or another Visual Studio instance in another session.

Solution 1

The easy solution to avoid further problems is to change the “Output path” to another location, for example, the default “bin\Development\”

And then instead of referring the assembly from a folder, choose Add reference from Projects

Visual studio 2003 add reference from project

Work like a charm!

Solution 2

Close all the Visual Studio solution that reference this assembly or assemblies and build the project.

Author: Sandro Pereira

Sandro Pereira lives in Portugal and works as a consultant at DevScope. In the past years, he has been working on implementing Integration scenarios both on-premises and cloud for various clients, each with different scenarios from a technical point of view, size, and criticality, using Microsoft Azure, Microsoft BizTalk Server and different technologies like AS2, EDI, RosettaNet, SAP, TIBCO etc. He is a regular blogger, international speaker, and technical reviewer of several BizTalk books all focused on Integration. He is also the author of the book “BizTalk Mapping Patterns & Best Practices”. He has been awarded MVP since 2011 for his contributions to the integration community.

1 thought on “The file ‘…’ cannot be copied to the run directory. The process cannot access the file because it is being used by another process.”

Leave a Reply to Andy Cancel reply

Your email address will not be published.

BizTalk360
BizTalk Server

Over 650+ customers across
30+ countries depend on BizTalk360

Learn More
Serverless360
Azure

Operate efficiently with enterprise-grade Azure monitoring,
tracing, remediation & governance in one platform

Learn More

Back to Top