views:

103

answers:

2

I am running an external process in a custom msbuild task. This task is in assembly A which is called when I'm building project B. Everything works fine. However, when trying to clean the project. Visual Studio 2008 gives me an error saying "the process cannot access assembly A because it is being used by another process". Restarting Visual Studio fixes this problem.

The code calling the external process is as follows

Process process = new Process();

process.StartInfo = new ProcessStartInfo { FileName = @"c:\program.exe", Arguments = "", UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = true, RedirectStandardError = true };

process.Start();

process.WaitForExit(5000);

How do I troubleshoot a problem like that?

Update: Using Process Explorer, it tells me devenv.exe has a handle on assembly A. Why and how do I stop it from having a handle on it?

+1  A: 

I am not entirely sure of the goal of your question. You can use process explorer to find out which process is locking the file.

Something like here : http://windowsxp.mvps.org/processlock.htm

Jeremy White
That's a nice tool. However, it just says devenv.exe has a handle on it.
seanlinmt
I guess my original question was answered by you. I will create another question for the current problem since it is clearer now. Thanks.
seanlinmt
A: 

That is sort of normal… devenv.exe is executing the process but the handles are still there. I'm not sure how can you avoid that, but I'm sure that after a few minutes the handle may go away.

I'm not sure if Garbage Collection has anything to do with it, but have you tried something like this?:

using (Process process = new Process()){

process.StartInfo = new ProcessStartInfo { FileName = @"c:\program.exe", Arguments = "", UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = true, RedirectStandardError = true };

process.Start();

process.WaitForExit(5000);
}

That will at least set the scope of the object.

Martín Marconcini
yes, I did. Same problem. I guess I will just need to remove the external process and bits of other things until I narrow down the problem.
seanlinmt