views:

178

answers:

2

Hi, I have a c# Windows Forms application that runs perfectly from within Visual Studio, but crashes when its deployed and run from the .exe. It crashes with a Buffer Overrun error...and its pretty clear that this error is not being thrown from within my code. Instead, windows must be detecting some sort of buffer overrun and shutting down the application from the outside. I don't think there's one specific line of code that is causing it..it simply happens intermittently.

Does anybody have any thoughts on what the possible causes of a Buffer Overrun error might be, and why it would only occur in the deployed application and not when run from with Visual Studio?

Thanks in advance, Ben

A: 

You have to be more specific.

Usualy you have some buggy unmanaged code.

tsinik
The exact error is:A buffer overrun has occurred in MyApplication.exe which has corrupted the program's internal state. Press Break to debug the program or Continue to terminate the program.It's hard to provide code...I can't determine where it's crashing! I'm in the process of adding logging statements to virtually every line of code, but so far I still haven't detected a pattern.
Ben
Why don't you "Press Break to debug the program" as the error states? Why don't you try to attach your application to the debugger in Visual Studio (of course, your application should be running in debug mode not in release mode)? Are you using unsafe code blocks?
Sameh Serag
+1  A: 

This is an error that's caused by mis-behaving unmanaged C/C++ code. The unmanaged CRT verifies that code doesn't overrun the end of an array located on the stack by storing a cookie in the stack frame. When a function returns, it checks if the cookie is still there. If it isn't, it assumes some kind of malicious code or a bug in the C/C++ code has destroyed the stack frame. Fair assumption, that's how most virus infections worked in late nineties.

The odds are about 99.999% that this is a bug in the C/C++ code, 0.001% that the machine is under attack. You'll need to find that C/C++ code and get a hold of the programmer that wrote it to get the bug fixed. If you have no clue where to look, start by suspecting any kind of ActiveX control or COM server. And attach a debugger in unmanaged mode to a running version of your program to see what DLLs it has loaded. Use Debug + Windows + Modules and verify that you can account for all DLLs.

Oh, and the crash details would be verify helpful to localize the source.

Hans Passant