简体   繁体   English

XP上的C#应用​​程序崩溃

[英]C# Application Crashes on XP

Last 3 months I was developing C# app on Windows 7 in VS2010. 最近3个月,我正在VS2010中在Windows 7上开发C#应用程序。 Now its almost done and I found out its not able to run on XP. 现在它几乎完成了,我发现它不能在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. Standart Windows“发送/不发送”错误没有对问题进行具体说明。

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.) 谢谢(顺便说一句,我在两台计算机上都安装了Framework4。我的其他.NET应用程序运行正常。)

[SOLUTION] Problem was in LineShape I've created in VS10 as part of GUI. [解决方案]问题是我在VS10中作为GUI的一部分创建的LineShape。 These lines cause crashing I dont know why. 这些行导致崩溃,我不知道为什么。 As It turned out, it was not OS problem, similar problem was on W7 and Vista. 事实证明,这不是操作系统问题,W7和Vista上也存在类似问题。 Basicly every Pc were wasnt VS instaled :) 基本上每个PC都不是VS安装的:)

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. 在应用程序中某个位置的静态虚拟初始化器属性中注册Appdomain.UnhandledException事件,然后在将其扔回到环境之前在处理程序中处理/输出该事件。 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;
    }

At your application's main , handle application domain exceptions and application thread exception in the code and then diagnose it like: 在您的应用程序的main ,处理代码中的应用程序域异常和应用程序线程异常,然后像下面进行诊断:

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). 我打赌您正在使用P / Invoke或混合模式程序集(使用不安全或本机代码)。

There could be a platform difference (think of differences between 32/64 bitness, but also missing/changed API calls). 可能存在平台差异(请考虑32/64位之间的差异,但API调用也会丢失/更改)。

To find out the most likely spot(s) in your code, I have a slightly unorthodox recommendation: run it through the MoMa analyzer ( link ). 为了找出您的代码中最可能出现的位置,我提出了一个不合常规的建议: 通过MoMa分析器链接运行它

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). MoMa分析器旨在检测在跨平台Mono框架(在Unix,MAC,Windows甚至iOS和Android平台上可用)运行针对MS.NET Framework开发的应用程序时可能出现的可移植性问题。

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. 您当然可以忽略报告为“未在Mono上实现”的项目-因为这不是问题。 However, it will find all funny uses of P/Invoke and such things that may point you at the issue. 但是,它将发现P / Invoke的所有有趣用法,以及可能会引起您问题的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM