I Cant Run EXE File Outside of Visual Studio - c#

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.

Related

Can't built my Console Application

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

Pressing F5 in Visual Studio 2010 Builds but does not Launch Application

I have a Click Once application (WPF) in C#. Initially when I would hit F5 to debug/launch the application it worked smoothly. Eventually, F5 only would build the solution and not launch the application (therefore I could not step through my code). For a short while I switched from Debug to Release mode and for some reason that allowed the application to launch after using F5 and I could step through my code again. But now that no longer works either. Long story short, I cannot get the application to run in a manner that allows me to step through the code. I can only do a Start without Debugging (Ctrl + F5). Obviously this doesn't do much for me other than tell me if the application works or not.
The thing that worked for me today was to open Task Manager and look for any debug programs that didn't terminate properly.
Task Manager > Processes > kill all programs "*.vshost.exe *32"
You probably have lost your start up project in the solution, or the start up project is messed up, and no correct "item" is defined for the startup.
Right click on one of your projects, and select : define as startup project.
Then retry that should do the trick. If not, check in that projects properties to see if a form or something is defined as the startup object for that project.
Edit : Obviously dont define a class library project as startup project, but choose your UI :).
I had this same issue today and came here looking for help. I tried all the suggestions here and nothing helped.
Seeing as my solution was a simple console application I recreated it from scratch. The new solution didn't exhibit the problems, so I started comparing the two.
I reset the solution and project files so that they were identical (apart from Project GUID, name and root namespace) but the first solution still didn't run.
I then tried deleting the suo files, and the bin and obj folders. Still the first solution wouldn't run.
Finally, I noticed the vshost.exe process was still running for the project. When I killed that and reloaded, it all started working correctly.
I just had this problem today. The solution turned out to be a slight twist on the issue with *.vshost.exe mentioned previously.
I could build the application just fine but msvs refused to launch it. I could manually launch the application and the time stamp on the file indicated that it was in fact a fresh build as well. *.vshost.exe wasn't showing up in the task manager, so I couldn't end the process as suggested.
When all else failed, I tried deleting the .exe's and found that *.vshost.exe would not delete because it was in use. The error message indicated that it was actually the steam client (third party software) that had somehow grabbed my *.vshost.exe file and was "using" it. Not sure how or why. At any rate, I completely shut down steam, then it let me delete *.vshost.exe. After that, building and running from msvc worked normally.
Had the same issue, eventually tried deleting all breakpoints and the debug started working again. Yet to figure out why, but at least it works.
As well as the ghost *.vshost.exe. It could also be that you have the same Solution/Project open in another version of VS. I had the same Solution open in both VS2010 and VS2015 and when running in VS2010 it compiled but failed to start. Closing the VS2015 Solution and it ran as expected.
After years of using VS 2008, I suddenly had the F5 problem not launching the application. There must be a dozen different suggestions out there - I tried a few. Someone suggested a virus. My Microsoft Security Essentials was not automatically updating (a common problem it seems), so I manually updated it. It found a virus, removed it, and the F5 problem went away !
Had this problem and tried to delete everything in bin/debug folder but could not delete vshost.exe file - kept requesting admin permission and then still could not remove it even though running from admin account. Restarted and file was gone and f5 worked again

C# App runs in Visual Studio but after I build it crashes on execution?

I'm coding an application on C#, and it runs perfectly fine when I click the "Run" button in Visual Studio C# Express 2010. But, when I go to Debug -> Build Solution, after I run the .exe file, it says "XXX.EXE has stopped working..."
I have inserted break-points and commented out chunks of my code, rebuilt the project, and ran again to try to isolate the problem, but I can't figure out what is causing this. The fact that it runs fine in debug mode is strange.
Some things to try:
Check the system Event log for ASP.NET errors.
Try setting the build to Release mode and using Run--no debugging. See if it crashes then. Watch the Output and other windows for any errors during/after the crash. Depending on those results, check that your solution and project properties are correct in both Debug and Release configurations.
You can also build in debug mode, launch it externally, than attach the Visual Studio debugger to the process. But of course if it crashes on startup than that won't work.
You can add Debug.Assert lines to see if you can get one of those to throw.
Wrap your code in a big try/catch and make sure your catch handler somehow reports or logs the full exception for you.
Adding logging would be good idea. You can log to a file or the system event log. I suggest log4net or similar logging tool for that.
I just had this issue and was going to see if I could catch when the error happened via a console window, when I changed my app to console based the program stopped crashing, I commented out all Console writes and set it back into a windows forms app and voila, runs fine now.
-I know its an old post, but its open and unanswered so I think its fair game.
Try adding your application to your Antivirus Whitelist or exclusion list. This is a known problem with McAfee and Avast!
I may be misunderstanding the problem, but if you are trying to run your app from its .exe file (originally located at Visual Studio ####\Projects\ProjectName\bin\x86\Debug\ProjectName.exe), you must make sure that that .exe file is in that original directory. You cannot move it. I ran into a similar problem with XNA projects. If you want to move the.exe file somewhere else, you can create a shortcut to it, but don't ever move it. If you try and run it from a different location, or if you move any of the other files from that directory, you'll get an error message exactly like the one you described.
Also note that some Visual Studio projects (like XNA ones) will not run as standalones. Building the projects doesn't export them into a standalone format, they can only run on computers that have VS and all the projects framework installed, and their .exe file must remain in its original place.

Visual C# 2010 Express keeps File Handle after Debugging

After debug, in about 90% of the cases I can't rebuild my solution, because VS keeps the file handle of the old .exe (can't copy the new exe from obj\Debug to bin\Debug). I know that it's VS's file handle for sure, since I checked it with the Unlocker Assistent. Also, I tried the workaround with calling the default namespace the same es the executable, but no luck. Any ideas?
PS: Running it on Windows XP.
Seems to be a bug in VS since 2005. A google search will show MANY posts about this problem that Microsoft has yet to address. It hits me every so often as well when the IDE won't let go of a dll. Unfortunately a restart of VS is required :(

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