"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....

Leave a Comment

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