Can't built my Console Application - c#

From time to time I receive this error message when I'm debugging my Console Application:
The process cannot access the file 'bin\Release...' because it is
being used by another process. Exceeded retry count of 10. Failed.
The fact is that it's not running and Visual Studio keeps showing this message, and so I have to restart it and build it again.
The process is NOT running, so there is no reason to receive this error.
Does anyone know why this is happening?

Verify that nothing has changed the file permissions, and the file isn't read-only. Verify that you cannot delete the file yourself. If so then yes, something is blocking it.
Download handle.exe, which is a command-line tool that shows you what process is locking a file.
If handle.exe says nothing is using your file, or it says devenv.exe is using it, then I think you have hit that intermittent bug in Visual Studio. Your only option is to restart Visual Studio. If you do a google search for "used by another process" with site:connect.microsoft.com you will find that this bug gets reported, then fixed, then reported, then fixed - over many years. Personally, I have had this happen most often on VS2010 using WPF projects. It has yet to happen to me on VS2013. So upgrading might help.
Here is my Google search.

If the process is not running, I suppose Visual studio is the process that uses bin\Release.
If you want to know exactly what the problem is, delete everything in the folder (if possible), the file that will not be deleted will be the one that is used by Visual Studio, this will already be a good indicator.

I'm not sure why you are debugging the release build?
When this happens, it usually is due to being opened i.e. the console window that has ran the app is still open, or it is still in the process of closing.
However, again I feel it's due to debugging a release built application.

I had a similar issue in the last couple of days. The reason this happened to me is because I was testing a Windows Service I created. When I forgot to stop the service, and tried to build, I got this error.
Follow the suggestions in the other posts. As well, you may want to download Process Explorer from Microsoft - It might give you additional insight and allow you to kill any linger process.

What version of Visual Studio? You tagged it as VS 2013, correct?
Did you look at the following threads at Microsoft? Many complaining about similar issue.
https://connect.microsoft.com/VisualStudio/feedback/details/533411
http://connect.microsoft.com/VisualStudio/feedback/details/811846/visual-sudio-cant-complie
http://connect.microsoft.com/VisualStudio/feedback/details/647826

Related

Program Crashes Before First Line [duplicate]

I've built a .NET Windows Forms application in Visual Studio 2010. I also built a corresponding setup/install package via Visual Studio 2010. This is built as a 32-bit (x86) application. (We make use of third-party Windows Forms controls that are 32-bit only).
I am able to run the setup package and deploy successfully to other Windows 7 64-bit environments and 32 bit Windows XP boxes. The installed application runs fine on these.
However, when I attempt to run Windows Server 2008 R2 - 64 bit, the application crashes at startup. It installed successfully via the installer without any errors.
It appears to crash when loading the application. I put a message box as the first line in the application to see if it got past loading. The message box doesn't show up, so I assume that it occurs during loading/init of the application.
So far I haven't found much to go on. From the Details I see the following:
Exception Code: E0434352
I've fished around/googled to see if there was anything obvious, but I saw nothing. I saw some references to a possible stack overflow in the CLR.
The Windows Forms application is built with the following references:
DevExpress
Infragistics Winforms controls
ORACLE DataAccess DLL
RabbitMQ
What is the issue?
How do I approach figuring this out?
How do I debug to get more useful information?
If you are getting that error from Event Viewer, you should see another error event (at least one) from the Source ".NET Runtime". Look at that error message as it will contain the Exception info.
0xE0434352 is the exception code for all .NET exceptions so that won't tell you much. How did you got this exception code? The event log?
Your best bet is to use a debugger to get more information. If the Visual Studio debugger won't help you, then you might need to check out WinDbg with SOS. See here and here for an introduction. Let it break on the exception, and see if you can get more information on the why.
If you suspect it is an issue when loading assemblies you might want to check out the Fusion Log.
I'm not sure if this will help anyone or not, but since it was my problem, I figure it's worth mentioning:
I was getting this error, and it turned out to be a problem with the platform for which the EXE was built. We had it building for x86, and it needed to be x64, because of an Oracle reference in the project. When we made that change, the problem went away. So, see if you have any similar conflicts.
It looks like this error 0xe0434352 applies to a number of different errors.
In case it helps anyone, I ran into this error when I was trying to install my application on a new Windows 10 installation. It worked on other machines, and looked like the app momentarily would start before dying. After much trial and error the problem turned out to be that the app required DirectX9. Though a later version of DirectX was present it had to have version 9. Hope that saves someone some frustration.
I was fighting with this a whole day asking my users to run debug versions of the software. Because it looked like it didn't run the first line. Just a crash without information.
Then I realized that the error was inside the form's InitializeComponent.
The way to get an exception was to remove this line (or comment it out):
System.Diagnostics.DebuggerStepThrough()
Once you get rid of the line, you'll get a normal exception.
I was getting this when the app deployed. In my case, I chose "This is a full trust application" on the project security tab, and that fixed it.
Issue:
.Net application code aborts before it starts its execution [Console application or Windows application]
Error received: Aborted with Error code "E0434352"
Exception: Unknown exception
Scenario 1:
When an application is already executed, which have used some of the dependent resources and those resources are still in use with the application executed, when another application or the same exe is triggered from some other source then one of the app throws the error
Scenario 2:
When an application is triggered by scheduler or automatic jobs, it may be in execution state at background, meanwhile when you try to trigger the same application again, the error may be triggered.
Solution:
Create an application, when & where the application release all its resources as soon as completed
Kill all the background process once the application is closed
Check and avoid executing the application from multiple sources like Batch Process, Task Scheduler and external tools at same time.
Check for the Application and resource dependencies and clean up the code if needed.
To fix the issue for me (as a number of applications started to throw this exception all of a sudden, for example, CorelDraw X6 being one), I uninstalled the .NET 4.5 runtime and installed the .NET 4 runtime. The two versions cannot be installed side by side, but they use the same version numbers in the GAC. This causes issues as some of the functions have been depreciated in 4.5.
DLL Hell has returned...
We got this error when the connection string to our database was incorrect. The key to figuring this out was running the dotnet blah.dll which provided a stacktrace showing us that the sql server instance specified could not be found. Hope this helps someone.
So.. I had noticed in event viewer that this crash corresponded to a "System.IO.FileNotFoundException" error.
So I fired ProcMon and noticed that one of the program dlls was failing to load vcruntime140.
So I simply installed vs15 redist and it worked.
I know this is a somewhat old thread, but I had this problem too with a c#/WPF app I was creating. The app worked fine on the development machine, but would not start on the test machine. The Application Log in the Event Viewer gave a somewhat nebulous .NET Runtime error of System.IO.DirectoryNotFoundException.
I tried using some debugging software but the app would not stay running long enough to attach the debugger to the process. After banging my head against my desk for a day and looking at many web pages like this one, what I wound up doing to troubleshoot this was to install VS2019 on my test machine. I then dragged the .exe file from its folder (it was deep in the Users[user]\AppData\Apps\2.0... folder) to the open VS2019 instance and went to start it from there. Immediately, it came up with a dialog box giving the exception and the cause.
In my case, when I added an icon to one of the forms, the complete path to the icon was placed into the XAML instead of just the icon name. I had copied the icon file into the project folder, but since the project folder does not exist on the test machine, this was the root cause of the error. I then removed the path from the XAML, leaving just the icon name one, rebuilt the solution and re-published it, and it ran just fine on the test machine now. Of course there are many causes besides what gave me the error, but this method of troubleshooting should hopefully identify the root cause of the error, since the Windows Event Viewer gives a somewhat vague answer.
To summarize, use Visual Studio on the test machine as a debugger of sorts. But, to get it to work right, I had to drag the .exe file into the IDE and Start (run) it from there.
I believe this will also work with VS2017 as well as VS2019. Hopefully this helps someone who is still having this issue.
When running a command line application it would immediately exit, and I saw this exception in the Event Viewer but received no other feedback. In my case, running the command prompt as administrator solved the problem.
I believe one of the takeaways from this is simply that you may get this exception due to a permission issue.
A few hours later we had the identical exception with a newer version of the console application for a different reason. This time it turned out to be a dll version incompatibility. Using the required newer dll version solved the problem.
Perhaps this generic error comes up due to code that is not handling exceptions gracefully; with the best fix likely being to handle exceptions at least well enough to provide better error messages.
In my case, I was out of memory and my Windows System paging file was disabled. After re-enabling it the error went away.
In order to change the paging file settings:
Click Start, type Advanced System Settings into the Start menu and press Enter to open it.
Click the Settings button under performance.
Click over to the Advanced tab and click the Change button in the Virtual memory section.

I Cant Run EXE File Outside of Visual Studio

I appreciate that this question has probably been answered before, but I can't find the solution to my problem.
This is that I can't run my C# program by double clicking it in windows explorer. I have tried to run the release and debug versions, but no luck. The program runs without errors or warnings inside VS. I have tried completely rewriting my project in a different solution and it still doesn't work. When I do try to run it, it uses about 75MB in the RAM but then closes. A window comes up saying "Sending information to Microsoft".
Thanks in advance.
Edit:
I've tried making another project with just a form and nothing else
It runs ok inside VS but when I run the executable from windows explorer it launches but comes up with "GUI has stopped working" when you click on the close button. GUI is the name of the app. This happens with all of the projects that I make from now.
It sounds as if you are missing something vital which your EXE depends on. It is present when you run the application from the IDE, but not when you run it from Explorer.
Are you running it from the directory which it got compiled to? This is normally under your project, under "bin\Debug" or "bin\Release". If not, then the odds are that you are missing a file which is in that folder. Copy all the files (and any subfolders) to where your EXE lives, and that should fix the issue.
Another possibility is that you need a file which the IDE can find, but Windows cannot.
Debugging issues which cause a crash without a callstack are always tricky. I'd suggest that you add some logging to your app, so you can see what is going on prior to the crash. If the issue is caused by your code, then logging will help to find it.
Or, even quicker and dirtier, throw up a messagebox before every line. Give each one a unique message, and you can then investigate the code around the area of the last messagebox that you see before the crash.
It turns out, there was a problem with visual studio or windows. I was running a version of windows 10 but after the update that came on the 06/01/16 it works OK now.
My guess is that it was a problem with the universal windows extension in visual studio
Update:
As of about 7 months later visual studio is working very well on my new computer with windows 10. I also use the latest version on vs which may have been my problem Because my old machine was that: old. It may not have been compatible with the latest software.

vshost.exe not terminating properly in Visual Studio 2015

I am in charge of testing VS 2015 and how it works with our current applications for my employer. We currently use VS 2013 for everything we have, so I know there are no issues there. The problem I am having is that it appears the vshost.exe isn't terminating correctly or something. I have not narrowed down the exact issue but so far that is what I believe.
Here is how I get my error:
Run my app in debug
Open a few windows
Hit the "Stop Debug" button (the little red square)
Clean Solution
Rebuild Solution
After my rebuild I get the following errors in the EXE:
Error Could not copy "obj\Debug\APP.exe" to "..\..\bin\APP.exe". Exceeded retry count of 10. Failed.
Error Unable to copy file "obj\Debug\APP.exe" to "..\..\bin\CRM.exe". The process cannot access the file '..\..\bin\APP.exe' because it is being used by another process.
If I open the Task Manager and manually end the vshost.exe process I can successfully rebuild again, no issues. If I take the same steps, however, I am no longer able to build.
I tested these steps in 2013 and did not have an issue.
Also note that disabling the "Enable the Visual Studio hosting process" does alleviate the issue, however I do not want to disable this option.
Has anyone else had this issue? I know we are still early in release. Any suggestions/solutions to try? Is it possible there is something wrong in our code (which I highly doubt since I would then get the error in 2013, most likely).
Thanks for any help I receive!
EDIT: This is a WPF application written in .Net 4.0 using C#. Also, I have verified that the issue also occurs if I exit the application normally (IE I open a window then close it with the shutdown mode on LastWindowClosed)
SECOND EDIT: This is a new issue that presented itself in Visual Studio 2015 with the addition of the new live diagnostic tools.
I have found that if I have the "Enable Diagnostic Tools while debugging" option enabled in the debug settings I get this error. If I disable this option, the error goes away. I am not sure if this is a bug in Visual Studio but I would assume so, unless I need to do something else to shut them down properly. If anyone has comments or concerns, feel free to leave a note.
Probably late for the original question (and I see that he had a workaround), but as per MSDN, VSHOST.exe is only an enabler for improving Debug performance or facilitates scenarios such as partial trust debugging. If you do not need that support or can bear the cost of starting a process and attaching the debugger on each debug session, go ahead and disable the hosting process from project designer -> Debug -> Clear the box "Enable Visual Studio hosting process"

Process returns exit code -532462766 in Windows 8.1 [duplicate]

I've built a .NET Windows Forms application in Visual Studio 2010. I also built a corresponding setup/install package via Visual Studio 2010. This is built as a 32-bit (x86) application. (We make use of third-party Windows Forms controls that are 32-bit only).
I am able to run the setup package and deploy successfully to other Windows 7 64-bit environments and 32 bit Windows XP boxes. The installed application runs fine on these.
However, when I attempt to run Windows Server 2008 R2 - 64 bit, the application crashes at startup. It installed successfully via the installer without any errors.
It appears to crash when loading the application. I put a message box as the first line in the application to see if it got past loading. The message box doesn't show up, so I assume that it occurs during loading/init of the application.
So far I haven't found much to go on. From the Details I see the following:
Exception Code: E0434352
I've fished around/googled to see if there was anything obvious, but I saw nothing. I saw some references to a possible stack overflow in the CLR.
The Windows Forms application is built with the following references:
DevExpress
Infragistics Winforms controls
ORACLE DataAccess DLL
RabbitMQ
What is the issue?
How do I approach figuring this out?
How do I debug to get more useful information?
If you are getting that error from Event Viewer, you should see another error event (at least one) from the Source ".NET Runtime". Look at that error message as it will contain the Exception info.
0xE0434352 is the exception code for all .NET exceptions so that won't tell you much. How did you got this exception code? The event log?
Your best bet is to use a debugger to get more information. If the Visual Studio debugger won't help you, then you might need to check out WinDbg with SOS. See here and here for an introduction. Let it break on the exception, and see if you can get more information on the why.
If you suspect it is an issue when loading assemblies you might want to check out the Fusion Log.
I'm not sure if this will help anyone or not, but since it was my problem, I figure it's worth mentioning:
I was getting this error, and it turned out to be a problem with the platform for which the EXE was built. We had it building for x86, and it needed to be x64, because of an Oracle reference in the project. When we made that change, the problem went away. So, see if you have any similar conflicts.
It looks like this error 0xe0434352 applies to a number of different errors.
In case it helps anyone, I ran into this error when I was trying to install my application on a new Windows 10 installation. It worked on other machines, and looked like the app momentarily would start before dying. After much trial and error the problem turned out to be that the app required DirectX9. Though a later version of DirectX was present it had to have version 9. Hope that saves someone some frustration.
I was fighting with this a whole day asking my users to run debug versions of the software. Because it looked like it didn't run the first line. Just a crash without information.
Then I realized that the error was inside the form's InitializeComponent.
The way to get an exception was to remove this line (or comment it out):
System.Diagnostics.DebuggerStepThrough()
Once you get rid of the line, you'll get a normal exception.
I was getting this when the app deployed. In my case, I chose "This is a full trust application" on the project security tab, and that fixed it.
Issue:
.Net application code aborts before it starts its execution [Console application or Windows application]
Error received: Aborted with Error code "E0434352"
Exception: Unknown exception
Scenario 1:
When an application is already executed, which have used some of the dependent resources and those resources are still in use with the application executed, when another application or the same exe is triggered from some other source then one of the app throws the error
Scenario 2:
When an application is triggered by scheduler or automatic jobs, it may be in execution state at background, meanwhile when you try to trigger the same application again, the error may be triggered.
Solution:
Create an application, when & where the application release all its resources as soon as completed
Kill all the background process once the application is closed
Check and avoid executing the application from multiple sources like Batch Process, Task Scheduler and external tools at same time.
Check for the Application and resource dependencies and clean up the code if needed.
To fix the issue for me (as a number of applications started to throw this exception all of a sudden, for example, CorelDraw X6 being one), I uninstalled the .NET 4.5 runtime and installed the .NET 4 runtime. The two versions cannot be installed side by side, but they use the same version numbers in the GAC. This causes issues as some of the functions have been depreciated in 4.5.
DLL Hell has returned...
We got this error when the connection string to our database was incorrect. The key to figuring this out was running the dotnet blah.dll which provided a stacktrace showing us that the sql server instance specified could not be found. Hope this helps someone.
So.. I had noticed in event viewer that this crash corresponded to a "System.IO.FileNotFoundException" error.
So I fired ProcMon and noticed that one of the program dlls was failing to load vcruntime140.
So I simply installed vs15 redist and it worked.
I know this is a somewhat old thread, but I had this problem too with a c#/WPF app I was creating. The app worked fine on the development machine, but would not start on the test machine. The Application Log in the Event Viewer gave a somewhat nebulous .NET Runtime error of System.IO.DirectoryNotFoundException.
I tried using some debugging software but the app would not stay running long enough to attach the debugger to the process. After banging my head against my desk for a day and looking at many web pages like this one, what I wound up doing to troubleshoot this was to install VS2019 on my test machine. I then dragged the .exe file from its folder (it was deep in the Users[user]\AppData\Apps\2.0... folder) to the open VS2019 instance and went to start it from there. Immediately, it came up with a dialog box giving the exception and the cause.
In my case, when I added an icon to one of the forms, the complete path to the icon was placed into the XAML instead of just the icon name. I had copied the icon file into the project folder, but since the project folder does not exist on the test machine, this was the root cause of the error. I then removed the path from the XAML, leaving just the icon name one, rebuilt the solution and re-published it, and it ran just fine on the test machine now. Of course there are many causes besides what gave me the error, but this method of troubleshooting should hopefully identify the root cause of the error, since the Windows Event Viewer gives a somewhat vague answer.
To summarize, use Visual Studio on the test machine as a debugger of sorts. But, to get it to work right, I had to drag the .exe file into the IDE and Start (run) it from there.
I believe this will also work with VS2017 as well as VS2019. Hopefully this helps someone who is still having this issue.
When running a command line application it would immediately exit, and I saw this exception in the Event Viewer but received no other feedback. In my case, running the command prompt as administrator solved the problem.
I believe one of the takeaways from this is simply that you may get this exception due to a permission issue.
A few hours later we had the identical exception with a newer version of the console application for a different reason. This time it turned out to be a dll version incompatibility. Using the required newer dll version solved the problem.
Perhaps this generic error comes up due to code that is not handling exceptions gracefully; with the best fix likely being to handle exceptions at least well enough to provide better error messages.
In my case, I was out of memory and my Windows System paging file was disabled. After re-enabling it the error went away.
In order to change the paging file settings:
Click Start, type Advanced System Settings into the Start menu and press Enter to open it.
Click the Settings button under performance.
Click over to the Advanced tab and click the Change button in the Virtual memory section.

Error Creating Debug Information - Code Won't Compile

I'm using VS 2008. When ever I make a change in my code and try to compile I get the following error:
Error 7 Unexpected error creating
debug information file 'C:\Documents
and Settings\jbezanson\My
Documents\MyProjects\DispatchBoard\DispatchBoard\obj\Debug\DispatchBoard.PDB'
-- 'C:\Documents and Settings\jbezanson\My
Documents\MyProjects\DispatchBoard\DispatchBoard\obj\Debug\DispatchBoard.pdb:
The process cannot access the file
because it is being used by another
process. ' DispatchBoard
Using Process Explorer, it is always devenv.exe that is locking the file. If I run in Release mode this does not happen. It started 2 days ago when I started a WPF application, and since then it happens with every application I work on.
The only info I could find from Google was referring to a bug in VS 2003.
Anyone else have this problem? How do I fix it? It is getting very annoying having to kill the file handle every time I want to compile.
If you have multiple instances of VS open, close other instances (apart from the one you are trying to compile) - this may resolve the issue.
When I have problems with locked files, I use Unlocker. (If you tried everything and it's not working, try this ;)
In case of broken link, here's a mirror.
Have you tried closing VS, deleting obj folder then restarting VS?
I had the same problem this morning and noticed that I had another project open that had a reference to the one that would not compile or debug. I removed the reference (as I didn't actually need it) and it was fine.
I changed the 'StartUp Project' of my solution to a project without reference to the locked file's project.
This solved the issue for me using VS 2010 SP1.
(Process Explorer said msvsmon.exe (started by devenv.exe) locked the pdb file.
After changing the startup project the processes msvsmon.exe and .vshost.exe disappeared and so did the file handle.)
Alex Clark, thank you for pointing me in the right direction.
The only thing that worked for me is to remove the optimizeCompilations="true" attribute from on the compilation element in my Web.Config file.
Compilation time may be a little longer, but it worked well.
To avoid that problem just open the project properties, go to Debug tab an untick "Enable the Visual Studio hosting process"
I had this issue today. In my case, I had just grabbed the data from my company's source control and instantly hit this issue when I tried to compile the project. The issue ended up being that the \bin folder was set to Read Only. To solve the issue, I just made the folder not Read Only.
I just came across the same problem today. And then I realized what went wrong: I had couple of Visual Studio windows opened at the same time, and one of them was in debug mode.
When I stopped debug mode in that one, the problem was solved.
That happens when you have a "fistfull of VS windows" opened.
Right Click The Folder that contains debug .pdb and uncheck the folders read-only propertys then ok. thats it.
This works for me with web projects in Visual Studio Express 2012 for Web:
Press F5 to begin debugging
"Do you want to execute last successful build?" - hit YES
At this point you could try a request - not sure if this step is necessary
Hit the stop button
Recompile successfully
I have solved a similar problem by adding these lines as a pre-build event:
if exist "$(TargetPath).locked" del "$(TargetPath).locked"
if exist "$(TargetPath)" move "$(TargetPath)" "$(TargetPath).locked"
With proper modifications, it might help your problem.
Since you say you have it on all applications you work on it sounds like a more global problem. You could try and reinit the vs2008 by writing
devenv.exe /setup
Edit: link to command line options
This worked for me. What I done was that close my visual studio and delete the .suo file and then re-open the solution. The locking should be disappeared now. Cheers.
Old topic, but something that worked for me. I had 2 projects in my solution, a class library type project and a windows form project. The windows form project was referencing the compiled binary and not the project itself in my case which was causing the lock. After changing the reference to the class library project, it worked properly.
Not need to restart or delete the file.Deleting will not be possible , you will get error message. Just rename the file and that is enough.
VS2010 will create another file for you as it wont find the origional. :)
I had the same issue from time to time. Usually no problem but once in a while... This particular time, it was impossible to work. I would shut the application down, and even that didn't work most of the time. I saw this post and a person said they had no issues until they started a WPF application. I was playing music (radio station) in the background with Windows 8 "Music" app. I had the idea that it was a Microsoft App built with Visual Studio. Once I stopped playing music, I never encountered the error. If you are reading this, see if you have any Microsoft apps running.
I also had the same issue. Tried all the suggestions above with no luck. I eventually change the Build Configuration from Debug to Release, the solution built...
This problem started occurring for me after changing from Cassini to IIS Express as my platform for debugging.
Cassini was much better than IIS Express but doesn't properly support the Integrated pipeline. IIS Express is hopeless.
This seems to be some sort of race condition in Visual Studio or IIS Express. It is nothing to do with one project locking another project - the locks are coming solely from the activity of the web application's build process.
Anyways, none of the above solutions worked for me. Unlocker doesn't seem to be supported for Windows 8 anymore. So instead I tried LockHunter. What I do is keep the LockHunter app open all day. If I get a complaint about some file being locked I copy and paste the file path into LockHunter then try again. This usually sorts out the problem but sometimes takes a few attempts.

Categories

Resources