473,405 Members | 2,373 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

AppDomains and DllImport (C#)

I'm working with a set of experiments in a large system that is using AppDomains for isolation and wants to make a call out to an umanaged dll. The test dll has two methods, SetNumber(int num) and GetNumber(), and a global variable. The DllImport and getting and setting the numbers are fine.

The problem comes when I make the calls to the libraries from separate AppDomains. Calling SetNumber with 3 different values across 3 different AppDomains gives me the same value when I call GetNumber() on those domains. The .dll holds it values and behaves as a singleton implementation. Unfortunately, this isn't what we wanted!

Is there any way to get a legacy dll to run with a unique instance inside each AppDomain?

Some more information: in my struggles, I've found that there are 3 pretty decent ways to load Legacy dlls:

1) DllImport - The standard way to load DLL's specified at compile time.

2) LoadAssembly - along with GetProcAddress and FreeLibrary can load dlls on the fly. Note: You need a bit of hefty code to use the proc address in C#, code that declares a delegate and a struct and the Marshal class.

3) DynamicAssembly - I like this one the best: Allows you to load assemblies on the fly by creating a new assembly in the appdomain and pinvoking on that. Easily understandable if you have experience with reflection, usually.

Unfortunately all of these methods load up the DLL inside the main process and only once for this process. Any calls to that DLL from any AppDomains seem to be going to the very same DLL that was loaded into the overall process. Again, this is the behavior we're trying to kill, so does anyone have any ideas at all?
Oct 12 '07 #1
0 1570

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Daylor | last post by:
hi. i have mult thread vb.net application. it has 30 threads. each thread serves 1 phone caller. the question : is there a reason , to create appdomain for each Phone Service ? meaning 30...
4
by: Mountain Bikn' Guy | last post by:
I need some advice on this. I am working on a fairly complex calculator app (C#) with lots of functions (and these functions in turn use math functions from an unmanaged C DLL). A calculation takes...
0
by: Brian Takita | last post by:
Hello, I'm getting the following error at the end of this message when trying to run the ReportManager and the ReportServer: Assembly system.data.dll security permission grant set is...
2
by: Jody L. Whitlock | last post by:
Okay, I've banged my head against a wall for over a year now. Maybe I'm just a rock when it comes to this. I've got a new project, a Windows Service. The "application" itself is in a DLL that...
1
by: billr | last post by:
hi there, I hope that someone will be able to shed some light on little old confused me. We are developing an application which will be deployed onto a Terminal Server machine. The application...
8
by: Fred Mertz | last post by:
I'm working towards an MCTS cert and I'm having to learn a bunch of stuff that I doubt I'd stumble across on my own. One such feature of .NET is AppDomains; programatically creating new AppDomains...
3
by: | last post by:
If this is simple, forgive my ignorance, but I'm coming from the CompactFramework where we don't use AppDomains. I did a fair bit of archive searching and couldn't find an answer and I got no...
0
by: jeremyje | last post by:
I would like to create an application where I have many concurrent processes being managed by a monitoring process. Each process that is "managed" will be invoked from an assembly dll (think...
0
by: PRR | last post by:
Here is a code i found on "how to enumerate appdomains in a current process". The original code was posted by Thomas Scheidegger Add the following as a COM reference -...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.