DLL 运行时错误导致我的 C# 应用程序崩溃 - 如何避免它?

发布于 2024-07-27 05:19:30 字数 3030 浏览 3 评论 0 原文

在我的 Windows 应用程序中,我使用的是用 .NET DLL 包装的 C++ DLL(特别是 QuickFix 引擎)。 每天一次(不是在任何特定时间)运行时,内置类之一的构造函数之一会引发运行时错误。 即使错误被捕获并报告(到日志文件和数据库),我仍然会看到Windows“运行时错误”对话框(不提供恢复/调试选项),并且在按下“确定”按钮(唯一的一个)后可用)我的应用程序已终止。

当在调试、发布甚至在 VS2005 调试器本身中运行时,都会发生这种情况。

附带说明一下,我已在本地编译了上述 DLL(因为其中至少有一个包含基于 XML 规范自动生成的代码)。

任何人? (详细信息如下)

我的代码:

try
{
    QuickFix.Symbol Symbol = new QuickFix.Symbol();
    report.get(Symbol);
    PairsType instrument = ToPairType(Symbol.getValue());

    if (PairsType.NONE == instrument)
        return;

    QuickFix.MDEntryDate entryDate = new MDEntryDate();
    QuickFix.MDEntryTime entryTime = new MDEntryTime();
    QuickFix.QuoteCondition quoteCondition = new QuoteCondition();
    QuickFix.MDEntryPx MDEntryPxBid = new QuickFix.MDEntryPx();
    QuickFix.MDEntryPx MDEntryPxAsk = new QuickFix.MDEntryPx();

    QuickFix.NoMDEntries noMDEntries = new QuickFix.NoMDEntries();
    report.get(noMDEntries);

    for (uint i = 1; i <= noMDEntries.getValue(); ++i)
    {
        QuickFix44.MarketDataSnapshotFullRefresh.NoMDEntries group =
           new QuickFix44.MarketDataSnapshotFullRefresh.NoMDEntries();

        report.getGroup(i, group);

        if (group.isSetQuoteCondition())
            group.get(quoteCondition);
        if (group.isSetMDEntryDate())
            group.get(entryDate);
        if (group.isSetMDEntryTime())
            group.get(entryTime);

        switch (group.getMDEntryType().getValue())
        {
            case MDEntryType.BID:
                group.get(MDEntryPxBid);
                break;
            case MDEntryType.OFFER:
                group.get(MDEntryPxAsk);
                break;
        }
    }

    // use data...
}
catch (Exception e)
{
    // log the error
}

错误详细信息: 消息:外部组件引发异常 堆栈跟踪:

at FIX.message_order.=(message_order* , message_order* )
 at std._Tree_nod<std::_Tmap_traits<int,FIX::FieldBase,FIX::message_order,std::allocator<std::pair<int const ,FIX::FieldBase> >,1> >.{ctor}(_Tree_nod<std::_Tmap_traits<int\,FIX::FieldBase\,FIX::message_order\,std::allocator<std::pair<int const \,FIX::FieldBase> >\,1> >* , message_order* _Parg, allocator<std::pair<int const \,FIX::FieldBase> >* _Al)
 at std._Tree<std::_Tmap_traits<int,FIX::FieldBase,FIX::message_order,std::allocator<std::pair<int const ,FIX::FieldBase> >,1> >.{ctor}(_Tree<std::_Tmap_traits<int\,FIX::FieldBase\,FIX::message_order\,std::allocator<std::pair<int const \,FIX::FieldBase> >\,1> >* , message_order* _Parg, allocator<std::pair<int const \,FIX::FieldBase> >* _Al)
 at FIX.FieldMap.{ctor}(FieldMap* , Int32* order)
 at QuickFix.Group..ctor(Int32 field, Int32 delim, Int32[] message_order)
 at QuickFix44.MarketDataSnapshotFullRefresh.NoMDEntries..ctor()
 at PriceProviders.PriceProvider.onMarketDataRefresh(FixSession session, MarketDataSnapshotFullRefresh report)

Within my windows app, i'm using a c++ DLL wrapped with a .NET DLLs (specifically - the quickfix engine).
While running, once every day (not at any specific time), in one of the a constructor of one of the built-in classes throws a runtime error.
Even though the error is caught and reported (to a log file, and the database), I still get the windows 'runtime error' dialog (which offers no recovery/debugging options) and after pressing the 'ok' button (the only one available) my app is terminated.

This happens when running in Debug, Release and even while running within the VS2005 debugger itself.

As a side-note, I have compiled the above-mentioned DLLs locally (since at least one of them includes auto-generated code based on an XML specification).

Anyone? (details follow)

My code:

try
{
    QuickFix.Symbol Symbol = new QuickFix.Symbol();
    report.get(Symbol);
    PairsType instrument = ToPairType(Symbol.getValue());

    if (PairsType.NONE == instrument)
        return;

    QuickFix.MDEntryDate entryDate = new MDEntryDate();
    QuickFix.MDEntryTime entryTime = new MDEntryTime();
    QuickFix.QuoteCondition quoteCondition = new QuoteCondition();
    QuickFix.MDEntryPx MDEntryPxBid = new QuickFix.MDEntryPx();
    QuickFix.MDEntryPx MDEntryPxAsk = new QuickFix.MDEntryPx();

    QuickFix.NoMDEntries noMDEntries = new QuickFix.NoMDEntries();
    report.get(noMDEntries);

    for (uint i = 1; i <= noMDEntries.getValue(); ++i)
    {
        QuickFix44.MarketDataSnapshotFullRefresh.NoMDEntries group =
           new QuickFix44.MarketDataSnapshotFullRefresh.NoMDEntries();

        report.getGroup(i, group);

        if (group.isSetQuoteCondition())
            group.get(quoteCondition);
        if (group.isSetMDEntryDate())
            group.get(entryDate);
        if (group.isSetMDEntryTime())
            group.get(entryTime);

        switch (group.getMDEntryType().getValue())
        {
            case MDEntryType.BID:
                group.get(MDEntryPxBid);
                break;
            case MDEntryType.OFFER:
                group.get(MDEntryPxAsk);
                break;
        }
    }

    // use data...
}
catch (Exception e)
{
    // log the error
}

Error details:
Message: External component has thrown an exception
Stack trace:

at FIX.message_order.=(message_order* , message_order* )
 at std._Tree_nod<std::_Tmap_traits<int,FIX::FieldBase,FIX::message_order,std::allocator<std::pair<int const ,FIX::FieldBase> >,1> >.{ctor}(_Tree_nod<std::_Tmap_traits<int\,FIX::FieldBase\,FIX::message_order\,std::allocator<std::pair<int const \,FIX::FieldBase> >\,1> >* , message_order* _Parg, allocator<std::pair<int const \,FIX::FieldBase> >* _Al)
 at std._Tree<std::_Tmap_traits<int,FIX::FieldBase,FIX::message_order,std::allocator<std::pair<int const ,FIX::FieldBase> >,1> >.{ctor}(_Tree<std::_Tmap_traits<int\,FIX::FieldBase\,FIX::message_order\,std::allocator<std::pair<int const \,FIX::FieldBase> >\,1> >* , message_order* _Parg, allocator<std::pair<int const \,FIX::FieldBase> >* _Al)
 at FIX.FieldMap.{ctor}(FieldMap* , Int32* order)
 at QuickFix.Group..ctor(Int32 field, Int32 delim, Int32[] message_order)
 at QuickFix44.MarketDataSnapshotFullRefresh.NoMDEntries..ctor()
 at PriceProviders.PriceProvider.onMarketDataRefresh(FixSession session, MarketDataSnapshotFullRefresh report)

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

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

发布评论

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

评论(2

小鸟爱天空丶 2024-08-03 05:19:30

您可以在单独的 AppDomain 中加载 QuickFix DLL。 这将保护您的应用程序免遭意外终止。

您可以测试从主程序终止的应用程序域,并在需要时重新加载它。

应用程序域

http://msdn.microsoft.com/en-us/ library/system.appdomain.aspx

有关使用它们构建应用程序的更多信息

http://msdn.microsoft.com/en-us/library/yk22e11a(VS.71).aspx

我假设您无权访问 C++ 代码但。 恶心..多么令人讨厌的“石膏”修复。

You could load the QuickFix DLL in a separate AppDomain. That would protect your app from it terminating unexpectedly.

You could test for the app domain terminating from your main program and reload it when required.

App domain

http://msdn.microsoft.com/en-us/library/system.appdomain.aspx

A bit more info on building an app using them

http://msdn.microsoft.com/en-us/library/yk22e11a(VS.71).aspx

I'm assuming you don't have access to the C++ code but. Ick.. what a nasty "plaster" fix.

阪姬 2024-08-03 05:19:30

看起来您有一个堆栈跟踪指向 DLL 内的错误。
你有它的代码吗? 您可以将堆栈跟踪转发给的人是否支持它?

如果不修复 DLL 本身,问题将继续发生,除非您确定代码中导致崩溃的情况并解决它们 - 这不是推荐的解决方案,但有时是您无法控制代码时唯一可用的解决方案。

Looks like you have a stack trace pointing to a bug inside the DLL.
Do you have its code? Is it supported by someone you can forward the stack trace to?

Without fixing the DLL itself, the issue will continue to occur, unless you identify the cases in your code that cause the crash and work around them - not a recommended solution, but sometime the only one available when you do not control the code.

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