Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: VB.NET
Error   1   Unable to write to output file 'C:\Projects\VariantsReportFinal\VariantsReportFinal\obj\x86\Debug\VariantsReportFinal.exe': The process cannot access the file because it is being used by another process.     VariantsReportFinal
I have been using vs2008 and vs2010 and both give this error.
I have tried moving the output and the solution but I still find the error after running it successfully once.
I have also tried closing it in task manager,but it doesn't show the processes in task manager.
Can anyone help?
Thank you
Posted 1-Oct-12 23:11pm
Edited 2-Oct-12 1:10am
Joan Murt82.8K

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Probably, it is because your application is still using the file. Check where you create it, and make sure that all file related items are closed and Disposed - otherwise they will remain open until the Garbage Collector comes round and removes them, or your application closes.
Member 9374423 at 2-Oct-12 4:31am
I have restarted the application and even the computer. the error still occurs
OriginalGriff at 2-Oct-12 5:19am
That doesn't surprise me - if your application is creating the file each time, it will indeed be in use. As I said - look at where you create it!
Member 9374423 at 2-Oct-12 5:46am
directory is valid and on my local machine
OriginalGriff at 2-Oct-12 5:51am
I'll count to ten...

...When you create a file, if you do not close all streams and such like file objects which are involved, they remain open until the Garbage Collector is activated because .NET needs more memory. This may not happen until next week, or your application is closed. If you try to access the file before the streams have been disposed, the file is still open and in use by the stream, and cannot be copied or opened for writing.
Member 9374423 at 2-Oct-12 5:54am
Please be patient as I am still a junior.
I understand what you are saying. is there a way for me to close all the connections and streams and so on manually?
OriginalGriff at 2-Oct-12 6:01am
I am being patient! :laugh:
Yes - call the Dispose method for all such objects, or (better) enclose them in a using block so that they are automatically Disposed when they go out of scope.
Member 9374423 at 2-Oct-12 6:03am
Could you maby give just an example of this?
OriginalGriff at 2-Oct-12 6:14am
Sorry - but I have no idea what code you are using! So I can't provide any specific examples :laugh:
What are you using to create the file?
Member 9374423 at 2-Oct-12 6:15am
well its actually the solution that's giving the error when I run it
OriginalGriff at 2-Oct-12 6:20am
Sorry - that makes no sense to me.
Do you mean the VS solution? If so, exactly what are you doing?
Member 9374423 at 2-Oct-12 6:24am
Yes,Whenever I create a new project,after a while of editing,it will give the error above

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 5,170
1 DamithSL 4,357
2 Maciej Los 3,750
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,851

Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 2 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100