473,788 Members | 2,814 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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?
Jan 10 '07 #1
2 2318

"Dave Burns" <db********@aol .comwrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
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?


Jan 10 '07 #2
Thanks,

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

dave

"Ben Voigt" <rb*@nospam.nos pamwrote in message
news:uP******** ******@TK2MSFTN GP02.phx.gbl...
>
"Dave Burns" <db********@aol .comwrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
>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?



Jan 12 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
6208
by: Daylor | last post by:
in win32 process , when u create new process,u have new main thread. i know,appDomain r logical procces,that exists in 1 win32 process. the q: is there way to create second appDomain (the first 1 is the defualt appDomain) with his new ("main") thread ? if not ,what is the easy and clear way to create new thread on the new appDomain ?
5
15376
by: Chris | last post by:
Hi I have a scenario where I've created another AppDomain to dynamically load a DLL(s) into. In this newly loaded DLL I want to call a static method on a class. The problem arise is that I have the same class/static method definition statictly linked to my EXE and when I call InvokeMember(...), even though I got the Type from the new AppDomain, it calls the static method that I am staticly linked to and not the static method in the dynamicly...
15
11789
by: Bryan | last post by:
I have a multi-threaded C# console application that uses WMI (System.Management namespace) to make RPC calls to several servers (600+ ) and returns ScheduledJobs. The section of my code that performs the query is contained in a delegate function that I execute via a second thread. On 1 or 2 of the 600+ servers the query hangs. I've tried to use Thread.Join() coupled with a Thread.Abort() but this does not kill the thread. Based on...
8
3516
by: Bern McCarty | last post by:
Is it at all possible to leverage mixed-mode assemblies from AppDomains other than the default AppDomain? Is there any means at all of doing this? Mixed-mode is incredibly convenient, but if I cannot load/unload/reload extensions into my large and slow-to-load application during development without restarting the process then the disadvantages may outweigh the advantages. I've got a mixed-mode program in which I create a new AppDomain...
4
9882
by: Tim Menninger | last post by:
Just started working on this and have not found any real good resources out there. We have a lot of native C++ Dll code that we use for our app. We want to share the code so that C# ASP.net code can use the same business logic as our C++ client. Here are some questions: 1) Is there a way to call into native C++ classes directly? Meaning we do not have C API. I believe we could use a C API using the in C#. 2) If can't do #1, do we need...
1
2605
by: H.B. | last post by:
Hi, I need to make a function that can display data on my Managed C++ app and be called by an unmanaged C++ DLL. Something like : void Form1::Form1_Load(System::Object * sender, System::EventArgs * e) { MyDLLInit(MyAppDisplayFunction); }
2
1199
by: RalphTheExpert | last post by:
This thread is a continuation of a thread with the Subject "Unhandled exception - Different under debugger and non-debugger". (http://www.dotnetnewsgroups.com/newsgroupthread.asp?ID=186902) Oleg and Carl: Carl wrote: "I would think the only fully sanitary, guaranteed to work way would be to either terminate the program from inside the handler, or
2
1824
by: Dave Burns | last post by:
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...
2
3474
by: siger99 | last post by:
Hi, I try to use a 3rd party assembly ( basically a layer of managed C++ around a native C++ lib). Unfortunately, it was developped for NET 1.1 and knows only the default AppDomain. When I try to call it from another AppDomain, I get the "Cannot pass a GCHandle across AppDomains" error.
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10173
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9967
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4070
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3674
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.