简体   繁体   English

c#应用程序遇到问题并且没有明显原因关闭。 第三方dll可能存在的问题

[英]c# application encountering a problem and closing for no apparent reason. Possible problems with 3rd party dlls

We're building ac# application which will sit on PC's in garbage trucks. 我们正在构建ac#应用程序,它将位于垃圾车的PC上。 Things work fine on our development machines but as always, problems start to arise when we deploy onto our target hardware. 事情在我们的开发机器上运行良好,但一如既往,当我们部署到目标硬件上时,问题就开始出现了。

One in particular is giving us headaches. 尤其令人头疼的是。 At random intervals we will get a windows message box popping up and saying that our application has encountered a problem and needs to be closed. 在随机的时间间隔,我们将弹出一个Windows消息框,说我们的应用程序遇到了问题,需要关闭。

The application still works fine while the dialog box is sitting there, and obviously it closes when you click the close button. 当对话框位于那里时,应用程序仍然可以正常工作,当您单击关闭按钮时,它显然会关闭。 The frustrating thing is we get no exceptions, nothing in any logs, nothing in the system activity log. 令人沮丧的是,我们没有任何例外,任何日志中都没有,系统活动日志中没有任何内容。 My hunch that there's some problem happening in a 3rd party library which we are using for GPS, which is a .net wrapper for an unmanaged dll which we've had problems with before. 我的预感是在我们用于GPS的第三方库中发生了一些问题,这是我们以前遇到问题的非托管dll的.net包装器。 What options do we have to try and debug this?? 我们有什么选择来尝试和调试这个? I'm relatively new to windows programming and wondering if there are programs we can use to track which parts of a dll are being called by our code. 我对Windows编程比较陌生,想知道是否有程序可以用来跟踪代码调用dll的哪些部分。

Cheers Nimai 干杯尼迈

I feel for ya, these things are very hard to debug when its likely to be a problem in the 3rd party native dll itself. 我觉得,这些东西很难调试,因为它可能是第三方原生dll本身的一个问题。

What you could do in the meanwhile to make your app a little more robust is to load up your Wrapper assembly into a dynamically loaded App Domain instead of straight into your app, that way the DLL will just bring down the app domain not your whole app. 同时你可以做的是让你的应用程序更加健壮,将你的Wrapper程序集加载到一个动态加载的App Domain中,而不是直接加载到你的应用程序中,这样DLL就会关闭应用程序域而不是你的整个应用程序。 You can then have some code to restart (the app domain) if required. 然后,您可以根据需要重新启动一些代码(应用程序域)。 Note this is not fixing your problem, but at least making the app a little more robust in the field. 请注意,这不是解决您的问题,但至少使该应用程序在该领域更加强大。

Note there are some hoops to jump through in terms of marshalling data between your app domains, but nothing too onerous. 请注意,在应用程序域之间编组数据方面有一些可以跳过的箍,但没有什么太繁重。

Edit: Here is a nice blog post that supplies a sample 编辑:这是一个很好的博客文章提供样本

  • Have you added a thread exception handler? 您是否添加了线程异常处理程序?
  • Are you logging exceptions? 你在记录异常吗?
  • What type of error handling do you have? 你有什么类型的错误处理?
  • What does the message box say (Title and text)? 消息框说的是什么(标题和文字)?
  • Is this a WinForms application? 这是一个WinForms应用程序吗?
  • Is the GPS component COM based? GPS组件是基于COM吗? If so, ensure valid arguments are being passed to it's functions. 如果是这样,请确保将有效参数传递给它的函数。
  • Is this a Win32 exception? 这是Win32的例外吗? (Does the message box say "Win32 exception") (消息框是否显示“Win32异常”)
  • Is this a COM exception? 这是COM例外吗?
  • Are you running a timer in your application that triggers the GPS component calls? 您是否在应用程序中运行触发GPS组件调用的计时器?
  • Are you running any type of timer in your application? 你在应用程序中运行任何类型的计时器吗?

Try logging all exceptions 尝试记录所有异常

    static void Main(string[] args)
    {
        Application.ThreadException += ApplicationThreadException;
        AppDomain.CurrentDomain.UnhandledException += CurrentDomainUnhandledException;

        //Your code would go here
        throw new Exception("a");
    }

    static void ApplicationThreadException(object sender, ThreadExceptionEventArgs e)
    {
        LogException(e.Exception);
    }
    static void CurrentDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
    {
        LogException(e.ExceptionObject);
    }

    private static void LogException(object exception)
    {
        //you could of course log anywhere
        EventLog.WriteEntry("ConsoleApplication1", exception.ToString(), EventLogEntryType.Error);
    }

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

相关问题 c#从任务栏中删除第三方应用程序 - c# remove 3rd party application from taskbar C#第三方申请允许在Skype上 - c# 3rd party application allow on skype C#类库,无法使用第三方DLL的详细信息注册App.Manifest - C# Class Library, Cannot register App.Manifest with details for 3rd party DLLs PyCharm第三方DLL中的IronPython - IronPython in PyCharm 3rd Party DLLs C# 将多个 web 引用添加到同一第三方的不同版本 API 时出现问题? - C# Problem adding multiple web references to different versions of the same 3rd party API? 如果可能,在C#中使用FtpWebRequest实现没有第三方dll的FTP / SFTP - Achieving FTP/SFTP without 3rd party dll with FtpWebRequest if possible in C# 在C#.NET Core的声明有效负载中使用自定义数据为第三方应用程序创建SAML声明 - Create SAML Assertion for 3rd Party Application with custom data in Assertion Payload in C# .NET Core 如何使用c#获取第三方应用程序按钮的句柄? - How to get the handle of 3rd party application's button using c#? 用C#开发应用程序的最佳第三方GUI框架是什么? - What is the best 3rd party GUI framework for application development in C#? 将C#3rd第三方应用程序安装到WM智能手机时出现“权限不足”错误 - “Insufficient permission” error while installing C# 3rd party application to WM Smartphone
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM