Calling from default AppDomain (native code) into another AppDomain (managed code), hosted by ASP.NE

Discussion in 'ASP .Net' started by Dave Burns, Jan 10, 2007.

  1. Dave Burns

    Dave Burns Guest

    Hello,

    We have a situation where a managed C++ assembly links with native C++ dll.
    There is a callback mechanism which calls back into the managed code
    asynchronously. Since native classes cannot hold onto a managed reference,
    we need to have a managed static member which we access during the callback
    and then get into the managed code.

    This works great in a console or WinForm app. But in ASP.NET it doesn't. The
    reason is that each web site is loaded into its own AppDomain.

    After some debugging we found out that the managed static is set on
    AppDomain 2, but the callback happens on AppDomain 1 (the default domain).
    When the callback code tries to access the managed static - it is undefined.

    We found a way to do a call into a different AppDomain, but only when you
    already have a reference to that AppDomain and we don't - there doesn't seem
    to be a way to enumerate AppDomains in a process.

    Has anybody else run into this?

    Is there a way to have ASP.NET (or the CLR) to not load the native code into
    the neutral domain, instead load it into each AppDomain?
     
    Dave Burns, Jan 10, 2007
    #1
    1. Advertising

  2. Dave Burns

    Ben Voigt Guest

    "Dave Burns" <> wrote in message
    news:%...
    > Hello,
    >
    > We have a situation where a managed C++ assembly links with native C++
    > dll.
    > There is a callback mechanism which calls back into the managed code
    > asynchronously. Since native classes cannot hold onto a managed reference,

    Why not? There's gcroot and HandleRef and so forth to help with that.

    > we need to have a managed static member which we access during the
    > callback
    > and then get into the managed code.
    >
    > This works great in a console or WinForm app. But in ASP.NET it doesn't.
    > The
    > reason is that each web site is loaded into its own AppDomain.
    >
    > After some debugging we found out that the managed static is set on
    > AppDomain 2, but the callback happens on AppDomain 1 (the default domain).
    > When the callback code tries to access the managed static - it is
    > undefined.
    >
    > We found a way to do a call into a different AppDomain, but only when you
    > already have a reference to that AppDomain and we don't - there doesn't
    > seem
    > to be a way to enumerate AppDomains in a process.
    >
    > Has anybody else run into this?
    >
    > Is there a way to have ASP.NET (or the CLR) to not load the native code
    > into
    > the neutral domain, instead load it into each AppDomain?
    >
    >
     
    Ben Voigt, Jan 10, 2007
    #2
    1. Advertising

  3. Dave Burns

    Dave Burns Guest

    Thanks,

    I tried gcroot as well, but same result - still can't call across
    AppDomains.

    dave

    "Ben Voigt" <> wrote in message
    news:...
    >
    > "Dave Burns" <> wrote in message
    > news:%...
    >> Hello,
    >>
    >> We have a situation where a managed C++ assembly links with native C++
    >> dll.
    >> There is a callback mechanism which calls back into the managed code
    >> asynchronously. Since native classes cannot hold onto a managed
    >> reference,

    > Why not? There's gcroot and HandleRef and so forth to help with that.
    >
    >> we need to have a managed static member which we access during the
    >> callback
    >> and then get into the managed code.
    >>
    >> This works great in a console or WinForm app. But in ASP.NET it doesn't.
    >> The
    >> reason is that each web site is loaded into its own AppDomain.
    >>
    >> After some debugging we found out that the managed static is set on
    >> AppDomain 2, but the callback happens on AppDomain 1 (the default
    >> domain).
    >> When the callback code tries to access the managed static - it is
    >> undefined.
    >>
    >> We found a way to do a call into a different AppDomain, but only when you
    >> already have a reference to that AppDomain and we don't - there doesn't
    >> seem
    >> to be a way to enumerate AppDomains in a process.
    >>
    >> Has anybody else run into this?
    >>
    >> Is there a way to have ASP.NET (or the CLR) to not load the native code
    >> into
    >> the neutral domain, instead load it into each AppDomain?
    >>
    >>

    >
    >
     
    Dave Burns, Jan 12, 2007
    #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. news
    Replies:
    0
    Views:
    444
  2. F. Prefect
    Replies:
    5
    Views:
    1,100
    Steven Cheng[MSFT]
    Oct 10, 2004
  3. draskin
    Replies:
    0
    Views:
    326
    draskin
    Jan 9, 2007
  4. Dave Burns
    Replies:
    0
    Views:
    414
    Dave Burns
    Jan 12, 2007
  5. Replies:
    1
    Views:
    418
    John Saunders
    Sep 13, 2008
Loading...

Share This Page