DLL运行时错误崩溃我的C#应用​​程序 - 如何避免呢?我的、错误、程序、DLL

2023-09-03 03:04:08 作者:待我穿越回古代灭了数学

在我的Windows应用程序,我使用的是C ++ DLL包裹着一个.NET的DLL(具体 - 入quickfix引擎)。 在运行时,每天一次(而不是在任何特定的时间),在内置类之一的构造函数之一抛出运行时错误。 尽管这些错误被捕获并报告(日志文件和数据库),我仍然得到了Windows的运行时错误对话框(其中不提供回收/调试选项)和$ P $后pssing的确定按钮(目前唯一可用的)我的应用程序将被终止。

这发生在调试,发布并运行在VS2005调试器本身的运行,即使而当。

作为一个侧面说明,我已经本地编译上述的DLL(因为它们中的至少一个包括基于XML规范自动生成code)中。

有人吗? (详情如下)

我的code:

 尝试
{
    QuickFix.Symbol符号=新QuickFix.Symbol();
    report.get(符号);
    PairsType仪器= ToPairType(Symbol.getValue());

    如果(PairsType.NONE ==仪)
        返回;

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

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

    对于(UINT I = 1; I< = noMDEntries.getValue(); ++ I)
    {
        QuickFix44.MarketDataSnapshotFullRefresh.NoMDEntries组=
           新QuickFix44.MarketDataSnapshotFullRefresh.NoMDEntries();

        report.getGroup(I,组);

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

        开关(group.getMDEntryType()。的getValue())
        {
            案例MDEntryType.BID:
                group.get(MDEntryPxBid);
                打破;
            案例MDEntryType.OFFER:
                group.get(MDEntryPxAsk);
                打破;
        }
    }

    //使用的数据...
}
赶上(例外五)
{
    //记录错误
}
 

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

 在FIX.message_order。=(message_order *,message_order *)
 在std._Tree_nod<std::_Tmap_traits<int,FIX::FieldBase,FIX::message_order,std::allocator<std::pair<int常量,FIX :: FieldBase&GT; &GT;,1 GT; >.{ctor}(_Tree_nod<std::_Tmap_traits<int\,FIX::FieldBase\,FIX::message_order\,std::allocator<std::pair<int常量\,FIX :: FieldBase&GT; &GT; \,1&GT; &GT; *,message_order * _Parg,分配器&LT;的std ::对&LT; INT常量\,FIX :: FieldBase&GT; &GT; * _Al)
 在std._Tree<std::_Tmap_traits<int,FIX::FieldBase,FIX::message_order,std::allocator<std::pair<int常量,FIX :: FieldBase&GT; &GT;,1 GT; >.{ctor}(_Tree<std::_Tmap_traits<int\,FIX::FieldBase\,FIX::message_order\,std::allocator<std::pair<int常量\,FIX :: FieldBase&GT; &GT; \,1&GT; &GT; *,message_order * _Parg,分配器&LT;的std ::对&LT; INT常量\,FIX :: FieldBase&GT; &GT; * _Al)
 在FIX.FieldMap。{}构造函数(FieldMap *,*的Int32顺序)
 在QuickFix.Group..ctor(的Int32场的Int32 DELIM,的Int32 [] message_order)
 在QuickFix44.MarketDataSnapshotFullRefresh.NoMDEntries..ctor()
 在PriceProviders.PriceProvider.onMarketDataRefresh(FixSession会议,MarketDataSnapshotFullRefresh报告)
 

解决方案

您可以加载DLL的QuickFix在一个单独的AppDomain。这将保护您的应用程序从它终止意外。

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

应用程序域

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

在使用它们建立一个应用程序多一点信息

http://msdn.microsoft.com/ EN-US /库/ yk22e11a(VS.71)的.aspx

我假设你没有访问C ++ code,但。伊克..什么讨厌的膏药的修复。

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)

解决方案

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.