DLL运行时错误崩溃我的c#应用程序 - 如何避免? [英] DLL runtime error crashes my c# app - how to avoid it?

查看:477
本文介绍了DLL运行时错误崩溃我的c#应用程序 - 如何避免?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Windows应用程序中,我正在使用一个包含.NET DLL的c ++ DLL(特别是quickfix引擎)。
运行时,每天一次(不在任何特定时间),其中一个内置类的构造函数会抛出运行时错误。
即使错误被捕获并被报告(到日志文件和数据库),我仍然得到Windows的运行时错误对话框(它不提供恢复/调试选项),并且按下确定按钮(只有一个可用)我的应用程序被终止。



当在Debug,Release中运行,甚至在VS2005调试器本身运行时,会发生这种情况。
$ b

作为旁注,我已经在本地编译了上述的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;
}
}

//使用数据...
}
catch(异常e)
{
//记录错误
}

错误详细信息:
消息:外部组件已抛出一个例外
堆栈跟踪:

 在FIX.message_order。=(message_order *,message_order *)
在std._Tree_nod< std :: _ Tmap_traits< int,FIX :: FieldBase,FIX :: message_order,std :: allocator< std :: pair< int const,FIX :: FieldBase> >,1 GT; >。{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 GT; >。{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)
在FIX.FieldMap。{ctor (FieldMap *,Int32 * order)
在QuickFix.Group..ctor(Int32字段,Int32分隔符,Int32 [] message_order)
在QuickFix44.MarketDataSnapshotFullRefresh.NoMDEntries..ctor()
在PriceProviders.PriceProvider.onMarketDataRefresh(FixSession会话,MarketDataSnapshotFullRefresh报告)


解决方案

您可以将QuickFix DLL加载到单独的AppDomain中。



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



应用程序域



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



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



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


$ b $我假设你没有访问C ++代码,但是。 Ick ..一个讨厌的石膏修复。


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.

这篇关于DLL运行时错误崩溃我的c#应用程序 - 如何避免?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆