I\'m using a VS 2005 app to interface against an unmanaged (Fortran) DLL. When I run the compiled executable straight from the command line, everything is fine - the DLL can
Might be that there is an unhandled exception. You could try to add the following code to handle all uncatched exceptions:
static void Main()
{
// Add a handler for the UnhandledExceptionEvent
AppDomain.CurrentDomain.UnhandledException +=
new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
static void CurrentDomain_UnhandledException
(object sender, UnhandledExceptionEventArgs e)
{
try
{
Exception ex = (Exception)e.ExceptionObject;
MessageBox.Show(ex.ToString(), "Error",
MessageBoxButtons.OK, MessageBoxIcon.Stop);
}
finally
{
Application.Exit();
}
}
The reason for the underlying problem is that you might have a different working folder when debugging so that your native library is not found.
I am using Visual C# 2010 Express. I was able to stop the vshost32 crashes by navigating to Project -> Properties. I clicked on the Debug tab and unchecked the "Enable the Visual Studio hosting process" checkbox.
I had problem with crashes of vshost32.exe the problem vanished when I checked the checkbox:
Properties -> Debug -> Enable unmanaged code debugging
Does it work for you?
EDIT: In more recent versions the option is called: Enable native code debugging
(thanks Qwerty01)
EDIT: It also seems to help in VS2008 (@Deacon Frost), VS2010 (@Alxandr).
Not sure but you can disable use of the visual studio hosting process from Properties -> Debug
download dependency walker http://www.dependencywalker.com/ use it to open up your dll, and see if it relies on other dlls that are not present in that folder.