C# Application crashes with Buffer Overrun in deployed (.exe) version, but not in Visual Studio

1k Views Asked by At

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

2

There are 2 best solutions below

2
On

You have to be more specific.

Usualy you have some buggy unmanaged code.

0
On

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.