"The process cannot access the file because it is being used by another process"

As you probably know there are several causes to that message. One of them is due to the fact that .NET cache in memory files that are larger then 64K, thus those files always being used by another process. One simple way to workaround this behavior is to change project build configuration from debug to release, to build the project and then switch back to debug configuration.

oops, thanks to Mordy Shachar!

Published Monday, February 23, 2004 1:18 AM by nattYGUR

Comments

# re: "The process cannot access the file because it is being used by another process"

Sunday, February 22, 2004 6:34 PM by Martin
Although it takes 5 minutes for Visual Studio to do that on a large project... :P

# re: "The process cannot access the file because it is being used by another process"

Monday, February 23, 2004 2:01 AM by Omer van Kloeten
Usually, in my experience, what locks the file is the same Visual Studio.NET instance that you're working with. What I usually do, if this isn't something repetative, is close the instance, delete the obj and bin directories and then reopen the solution.

I'm not sure about this, but I think this happens because you've got Copy Local set to true on that file somewhere in the solution.

# re: "The process cannot access the file because it is being used by another process"

Wednesday, April 07, 2004 10:16 AM by Shashank Naik
Create the file with FileShare.ReadWrite.

If you do not want to do sharable do something like :
CLS takes time to close file handles if you use Dtor in your class. Better option is implement IDisposble interface and close all file handles there.

# re: "The process cannot access the file because it is being used by another process"

Tuesday, April 13, 2004 8:45 AM by Hector
Hi!
What are the other causes? I have one file of 5k and I am having this problem too.
Thanks

# re: "The process cannot access the file because it is being used by another process"

Tuesday, April 27, 2004 2:28 AM by Stepos
Hi,

When I try to do a build, I get the error:

"The file 'bin\myassembly.dll' cannot be copied to the run directory. The process cannot access the file because it is being used by another process. Could not copy temporary files to the output directory."

I've tried the solutions in the knowledge base (318785) with no luck (checking for trailing backslashes, latest service packs).
I've heard that the dll size could be the issue, mine is 360kb (pdb is3078 kb).

Thanks for any help,
Stepos

# how to lock a file so that it cannot be accessed

Friday, April 30, 2004 9:13 PM by Satsat
Hi,
how to make a file not to be opened giving this error message-"The process cannot access the file because it is being used by another process".

Thank you

# re: "The process cannot access the file because it is being used by another process"

Monday, May 24, 2004 2:08 AM by JSH
http://support.microsoft.com/default.aspx?scid=kb;en-us;313512

# re: "The process cannot access the file because it is being used by another process"

Friday, June 25, 2004 12:19 AM by ShamusFu
This has happened to me now and again and I think I have found at least why I did it.

I created some custom component (like a datagrid) and added it to my toolbox. What this did was add my current own project to the 'references' of my own project. This sort of circular dependancy created this message (I was able to reproduce it several times).

Look at your references and make sure your own currn t project is not listed in the 'References'.

# re: "The process cannot access the file because it is being used by another process"

Wednesday, July 07, 2004 9:47 AM by Bobby
I have a wierd problem. My solution fails to build only in Release config, Debug is fine! I get the same *.dll is being used by another process error!
Any thought?
Bobby

# re: "The process cannot access the file because it is being used by another process"

Tuesday, May 29, 2007 3:15 PM by AlejoR

Hi,

I am having the same problem using then word library (2004). I need to open a doc or rtf file, then save them to html, and finally open it in order to save to a DB.

It works fine, but sometimes I get that message!!!

What can I do!?

# re: "The process cannot access the file because it is being used by another process"

Friday, August 24, 2007 4:13 AM by Anders

Hi!

I had the same problem in my C# .Net 2003 - windows application, and followed the URL that JSH supplied:

support.microsoft.com/default.aspx

The cause of my problems was that I tried to have the same output folder for more than one of my assembly projects.

I resolved my problem by setting all the projects outputfolders to Bin\Debug\ and then copy the .dll files to the folder that i wanted them in, by using post build events.

Good luck!

# re: "The process cannot access the file because it is being used by another process"

Sunday, April 27, 2008 9:50 AM by David G

Read ShamusFu comment!!!!!

he got it !

# re: "The process cannot access the file because it is being used by another process"

Thursday, September 11, 2008 6:04 AM by Bappa Malakar

I saw this error message when i was trying to upload an image using Dot Net File Up loader The error message is like "The process cannot access the file 'D:\project\Blog\User\UserPic\rosemerry.jpeg' because it is being used by another process.". Right now i don't know how to fix it.

Bappa Malakar

ibmbappa@gmail.com

# re: "The process cannot access the file because it is being used by another process"

Tuesday, April 14, 2009 5:25 AM by JenC

I have had the same issues as well but found that if I set the 'CopyLocal' to False on the dll's in question it sorted out the issue (see Omer van Kloeten comment).

# re: "The process cannot access the file because it is being used by another process"

Monday, May 04, 2009 5:14 AM by Savip

Sometimes antivirus software locks assemblies and the problem occurs. Just try to turn off antivirus security for build time, or add assemblies to trusted area in your antivirus application.

# re: "The process cannot access the file because it is being used by another process"

Tuesday, May 12, 2009 8:50 PM by ShawnR

Sweet.. all the pain and finally, it was the new Anti-virus I installed.  disabled that and everything compiled again.

I will look for a solution within my AV to disable scanning within my development directory.

# re: "The process cannot access the file because it is being used by another process"

Sunday, June 14, 2009 3:04 PM by Laurent

Same for me, the pb was Kaspesky Antivirus!! I disabled and now it's fine....

# re: "The process cannot access the file because it is being used by another process"

Monday, November 09, 2009 1:31 PM by Monty

hey,

Whenever I create an application in MS Blend3 + sketchflow,soon after its very first build,it creates .dll files in Debug folder.

and so does not allows to debug/build again, untill I go to debug folder and delete all the possible .dll.

but this is kind of temprory solution to my problem to start the debugging again.

I wonder if any permanent solution is possible to kill all those .dll once and for all.

# re: "The process cannot access the file because it is being used by another process"

Friday, December 11, 2009 2:31 AM by Thuong Nguyen

Just disable Kaspersky antivirus. It works. Thanks.

# re: "The process cannot access the file because it is being used by another process"

Thursday, February 04, 2010 4:25 AM by Colin Pickard

disabling McAfee antivirus also solves this problem.

# re: "The process cannot access the file because it is being used by another process"

Friday, February 26, 2010 6:31 AM by Dave K

It was my anti virus. (Nod32).  I unchecked the "scan on file creation" in the "Real time file system settings" and I can now build a deployment without this error message.  Hooray !

# re: "The process cannot access the file because it is being used by another process"

Thursday, May 13, 2010 4:16 AM by sudhanva

Put the part where you access the file in your applications inside of "using" statements to ensure such resources are released to the system

// C-Sharp

try

{

   using (StreamReader reader = new StreamReader(@"C:\file.txt"))

   {

       // do some reading

       reader.Close();

   }

}

catch (IOException)     // Should capture access exception

{

   // Show error; do nothing; etc.

}

# re: "The process cannot access the file because it is being used by another process"

Thursday, November 04, 2010 1:13 AM by Harshad

Hi,

I tried the reply by Omer (by deleting bin & obj directories and closing/opening the VS IDE again) and it worked fine.

# re: "The process cannot access the file because it is being used by another process"

Monday, December 13, 2010 10:08 PM by nemo

i just meet this problem,and look for answer for so long time  then no method to it ,if some one know how to solve it ,please contact me....thans very much,my MSN :mac.1106@live.cn

# re: "The process cannot access the file because it is being used by another process"

Sunday, March 20, 2011 11:42 PM by nuwan

close the solution and just remove the tick mark from read only from bin directory.

# re: "The process cannot access the file because it is being used by another process"

Sunday, March 20, 2011 11:51 PM by nuwan

close the VS solution and untick the read only option from the bin directory.

# re: "The process cannot access the file because it is being used by another process"

Friday, August 05, 2011 5:16 AM by bhaskarpimpalshende

can anybody tell me what is the exact root cause?

I dont think so it may be because of Anti virus.

# re: "The process cannot access the file because it is being used by another process"

Tuesday, May 15, 2012 8:43 AM by SEOHQAmzErzUTWZEIbX

YYy4tR Wow, great post. Will read on...

# re: "The process cannot access the file because it is being used by another process"

Monday, July 09, 2012 8:16 PM by JgCKoSlvDkAChCI

bkQZu2 Muchos Gracias for your article post.Really looking forward to read more. Will read on...

Leave a Comment

(required) 
(required) 
(optional)
(required)