Strange exceptions in ASP.NET + COM application

Discussion in 'ASP .Net' started by danil.shopyrin@gmail.com, Mar 13, 2006.

  1. Guest

    Hello!

    We have some code that is written in COM. It was used in a
    "ISAPI-extension server " and everithing was fine. And it is fine at
    the moment.

    But now this code is used from the ASP.NET server. And we receive some
    unknown exceptions. Them occurs after a long period of working (about
    of 10,000 stress-test-queries). We can't ever recognize these
    exceptions.

    For example, yesterday I've received an exception in the method:

    STDMETHODIMP CGobiSrv::put_FSCreator(IUnknown* fsCreator)
    {
    SAFE_METHOD_START("CGobiSrv::put_FSCreator")
    AFX_MANAGE_STATE(AfxGetStaticModuleState())
    serve->SetFSCreator( fsCreator );
    GTRACEL("FSCreator received\n");
    return S_OK;
    SAFE_METHOD_END
    }

    We try to catch exceptions using the following code:

    #define SAFE_METHOD_START(method_name) \
    CMethodExecutionViewer method_ex_viewer( this->GetClassID(),
    this->GetInstanceNum(), method_name ); \
    try { \

    #define SAFE_METHOD_END \
    } catch (std::exception& e) { \
    method_ex_viewer.ViewException( "standard", e.what() ); \
    return E_FAIL; \
    } catch (CException* e) { \
    const int MAX_ERR_LEN = 256; \
    GBuffer<TCHAR> err_msg(MAX_ERR_LEN); \
    e->GetErrorMessage( err_msg, MAX_ERR_LEN ); \
    method_ex_viewer.ViewException( _TEXT("MFC"), static_cast<TCHAR*>(
    err_msg ) ); \
    return E_FAIL; \
    } catch (_com_error &e) { \
    method_ex_viewer.ViewException( _TEXT("COM"), e.ErrorMessage() ); \
    return E_FAIL; \
    } catch (CAtlException &e) { \
    const int MAX_ERR_LEN = 256; \
    GBuffer<TCHAR> hr_code(MAX_ERR_LEN); \
    ltoa(e, hr_code, 16); \
    method_ex_viewer.ViewException( _TEXT("ATL"), static_cast<TCHAR*>(
    hr_code ) ); \
    return E_FAIL; \
    } catch (...) { \
    method_ex_viewer.ViewException( "unknown", "" ); \
    return E_FAIL; \
    } \

    and our exceptions are always fall into the catch (...) section.

    There is some EnterCriticalSection()/LeaveCriticalSection() that occurs
    in SetFSCreator() method because of the fact that some global data is
    shared between COM-objects. It's is because we use very legacy code.
    Maybe the error is somewhere in interlocking, but why it's working in
    the ISAPI-mode?

    We use _ATL_APARTMENT_THREADED. We tried to run ASP script with and
    without ASPCompat="true". We tried to run on .NET 1.1 and .NET 2.0. The
    song remains the same.

    It's very hard to debug. Because these exceptions occurs in different
    places and after a long time of working.

    Can anybody help us?

    --
    Danil
     
    , Mar 13, 2006
    #1
    1. Advertising

  2. Bruce Barker Guest

    you need to set AspCompat=true, to support STA (apartment model) com
    objects. also are you calling Marshal.ReleaseComObject(), to release the
    object?

    note: STA com objected can not be used directly from a webservice.

    -- bruce (sqlwork.com)


    <> wrote in message
    news:...
    > Hello!
    >
    > We have some code that is written in COM. It was used in a
    > "ISAPI-extension server " and everithing was fine. And it is fine at
    > the moment.
    >
    > But now this code is used from the ASP.NET server. And we receive some
    > unknown exceptions. Them occurs after a long period of working (about
    > of 10,000 stress-test-queries). We can't ever recognize these
    > exceptions.
    >
    > For example, yesterday I've received an exception in the method:
    >
    > STDMETHODIMP CGobiSrv::put_FSCreator(IUnknown* fsCreator)
    > {
    > SAFE_METHOD_START("CGobiSrv::put_FSCreator")
    > AFX_MANAGE_STATE(AfxGetStaticModuleState())
    > serve->SetFSCreator( fsCreator );
    > GTRACEL("FSCreator received\n");
    > return S_OK;
    > SAFE_METHOD_END
    > }
    >
    > We try to catch exceptions using the following code:
    >
    > #define SAFE_METHOD_START(method_name) \
    > CMethodExecutionViewer method_ex_viewer( this->GetClassID(),
    > this->GetInstanceNum(), method_name ); \
    > try { \
    >
    > #define SAFE_METHOD_END \
    > } catch (std::exception& e) { \
    > method_ex_viewer.ViewException( "standard", e.what() ); \
    > return E_FAIL; \
    > } catch (CException* e) { \
    > const int MAX_ERR_LEN = 256; \
    > GBuffer<TCHAR> err_msg(MAX_ERR_LEN); \
    > e->GetErrorMessage( err_msg, MAX_ERR_LEN ); \
    > method_ex_viewer.ViewException( _TEXT("MFC"), static_cast<TCHAR*>(
    > err_msg ) ); \
    > return E_FAIL; \
    > } catch (_com_error &e) { \
    > method_ex_viewer.ViewException( _TEXT("COM"), e.ErrorMessage() ); \
    > return E_FAIL; \
    > } catch (CAtlException &e) { \
    > const int MAX_ERR_LEN = 256; \
    > GBuffer<TCHAR> hr_code(MAX_ERR_LEN); \
    > ltoa(e, hr_code, 16); \
    > method_ex_viewer.ViewException( _TEXT("ATL"), static_cast<TCHAR*>(
    > hr_code ) ); \
    > return E_FAIL; \
    > } catch (...) { \
    > method_ex_viewer.ViewException( "unknown", "" ); \
    > return E_FAIL; \
    > } \
    >
    > and our exceptions are always fall into the catch (...) section.
    >
    > There is some EnterCriticalSection()/LeaveCriticalSection() that occurs
    > in SetFSCreator() method because of the fact that some global data is
    > shared between COM-objects. It's is because we use very legacy code.
    > Maybe the error is somewhere in interlocking, but why it's working in
    > the ISAPI-mode?
    >
    > We use _ATL_APARTMENT_THREADED. We tried to run ASP script with and
    > without ASPCompat="true". We tried to run on .NET 1.1 and .NET 2.0. The
    > song remains the same.
    >
    > It's very hard to debug. Because these exceptions occurs in different
    > places and after a long time of working.
    >
    > Can anybody help us?
    >
    > --
    > Danil
    >
     
    Bruce Barker, Mar 13, 2006
    #2
    1. Advertising

  3. Guest

    Dear Bruce,

    thank you for your reply.

    I try to use Marshal.ReleaseComObject(). I check the returm value and
    it always equals to 0.

    Exceptions are still here. The problem is that I don't know what to
    catch. I don't understand what's happened. I afraid that something is
    happened with the host aspnet_wp process.

    There is anonther question. Is there a way to 'reboot' aspnet_wp
    process sometimes? For example, one time for each 1000 requests. It can
    help to avoid the problem, if we can't solve them.
     
    , Mar 16, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ahmed Moustafa
    Replies:
    5
    Views:
    30,071
    Chris Smith
    Jul 14, 2004
  2. Paul Miller
    Replies:
    3
    Views:
    1,031
    Alex Martelli
    Nov 12, 2003
  3. Replies:
    3
    Views:
    620
    Sherm Pendley
    Apr 16, 2007
  4. Lie
    Replies:
    3
    Views:
    645
  5. dm1608
    Replies:
    11
    Views:
    2,921
    dm1608
    May 25, 2009
Loading...

Share This Page