[英]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 编辑:这是一个很好的博客文章提供样本
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.