Build Solution, after I run t" />
开发者

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

开发者 https://www.devze.com 2023-01-17 18:14 出处:网络
I\'m coding an application on C#, and it runs per开发者_开发知识库fectly fine when I click the \"Run\" button in Visual Studio C# Express 2010. But, when I go to Debug -> Build Solution, after I run t

I'm coding an application on C#, and it runs per开发者_开发知识库fectly 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消