C# Application Crashes on XP
Last 3 months I was developing C# app on Windows 7 in VS2010. Now its almost done and I found out its not able to run on XP. It crashes instantly and shows the message "Program encountered the problem and needs to be closed...". Standart windows "send / dont send" error say nothing开发者_如何转开发 specific about problem.
I can post code in here but there are literally thousands of lines and i dont know which part is important and which is not. Can someone tell me "usual suspects" which cause this problem ?
Thanks (btw i do have Framework 4 on both of my computers. My other .NET apps works fine.)
[SOLUTION] Problem was in LineShape I've created in VS10 as part of GUI. These lines cause crashing I dont know why. As It turned out, it was not OS problem, similar problem was on W7 and Vista. Basicly every Pc were wasnt VS instaled :)
At your application's main
, handle application domain exceptions and application thread exception in the code and then diagnose it like:
AppDomain.CurrentDomain.UnhandledException += OnCurrentDomain_UnhandledException;
//in windows forms you need also to add these two lines
Application.ThreadException += OnApplication_ThreadException;
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
I'd wager you are using P/Invoke or Mixed mode assemblies (using either unsafe or native code).
There could be a platform difference (think of differences between 32/64 bitness, but also missing/changed API calls).
To find out the most likely spot(s) in your code, I have a slightly unorthodox recommendation: run it through the MoMa analyzer (link).
The MoMa analyzer was designed to detect portability issues that may arise when running applications developed for/on the MS .NET Framework on the cross-platform Mono Framework (available on Unix, MAC, Windows and even iOS and Android platforms).
It will give you a nice report of things that are likely to cause problems. You can of course neglect the items reported as 'unimplemented on mono' - because that is not an issue. However, it will find all funny uses of P/Invoke and such things that may point you at the issue.
register for the Appdomain.UnhandledException event in a static dummy initializer property somewhere in your application, process/output the event in your handler before rethrowing it to the environment. if that doesn't help it's either another static member somewhere that got called before your handler got subscribed or.. "something else is wrong".
static bool dummy = RegisterUnhandledExceptionHandler();
private static bool RegisterUnhandledExceptionHandler()
{
AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
{
Exception ex = (e.ExceptionObject as Exception);
// quick dump to file because environment will exit soon
File.WriteAllText("unhandled.txt", ex.StackTrace);
throw ex;
}
return true;
}
精彩评论