C# 应用程序在 XP 上崩溃

发布于 2024-12-01 07:56:52 字数 378 浏览 1 评论 0 原文

过去 3 个月,我在 VS2010 中的 Windows 7 上开发 C# 应用程序。现在快完成了,我发现它无法在 XP 上运行。它立即崩溃并显示消息“程序遇到问题,需要关闭...”。标准窗口“发送/不发送”错误没有说明问题的具体情况。

我可以在这里发布代码,但实际上有数千行,我不知道哪一部分重要,哪一部分不重要。有人可以告诉我导致这个问题的“常见嫌疑人”吗?

谢谢 (顺便说一句,我的两台计算机上都有 Framework 4。我的其他 .NET 应用程序工作正常。)

[解决方案] 问题出在我在 VS10 中创建的 LineShape 作为 GUI 的一部分。这些行导致崩溃,我不知道为什么。事实证明,这不是操作系统问题,W7和Vista上也有类似问题。基本上每台电脑都没有安装VS:)

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 :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

痴者 2024-12-08 07:56:52

在应用程序的 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);

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);
旧话新听 2024-12-08 07:56:52

我敢打赌您正在使用 P/Invoke 或混合模式程序集(使用不安全或本机代码)。

可能存在平台差异(考虑 32/64 位之间的差异,以及丢失/更改的 API 调用)。

为了找出代码中最有可能的位置,我有一个稍微非正统的建议:通过 MoMa 分析器运行它 (链接)。

MoMa 分析器旨在检测在跨平台 Mono Framework(可在 Unix、MAC、Windows 甚至 iOS 和 Android 平台上可用)上运行为 MS .NET Framework 开发的应用程序时可能出现的可移植性问题。

它会给你一个关于可能引起问题的事情的很好的报告。您当然可以忽略报告为“未在单声道上实现”的项目 - 因为这不是问题。但是,它会发现 P/Invoke 的所有有趣用法以及可能会指出问题的此类内容。

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.

╰沐子 2024-12-08 07:56:52

在静态虚拟对象中注册 Appdomain.UnhandledException 事件应用程序中某处的初始化程序属性,在将事件重新抛出到环境之前在处理程序中处理/输出该事件。如果这没有帮助,则可能是在您的处理程序订阅之前调用了某个地方的另一个静态成员,或者......“其他问题”。

    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;
    }

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;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文