appdomain

Good example of use of AppDomain

I keep getting asked about AppDomains in interviews, and I know the basics: they are an isolation level within an application (making them different from applications) they can have threads (making htem different from threads) exceptions in one appdomain do not affect another appdomains cannot access each other's memory each appdomain...

How to unload an assembly from the primary AppDomain

I would like to know how to unload an assembly that is loaded into the main appdomain. I have the following code: var assembly = Assembly.LoadFrom( FilePathHere ); I need/want to be able to unload this assembly when i am done. Thanks for your help. ...

AppDomain And the Current Directory

I have a class that utilizes a directory swap method for the Environment.CurrentDirectory. The code looks something like this: var str = Environment.CurrentDirectory; Environment.CurrentDirectory = Path.GetDirectoryName(pathToAssembly); var assembly = Assembly.Load(Path.GetFileNameWithoutExtension(pathToAssembly)); Environment.Curr...

Runtime callable wrapper (RCW) scope - process or application domain?

What is the scope of Runtime Callable Wrapper (RCW), when referencing unmanaged COM objects? According to the docs: The runtime creates exactly one RCW for each COM object, regardless of the number of references that exist on that object. If I had to "guess" - this explanation should mean "one per process", but is it really? ...

How do I obtain a list of the application domains my application has created?

I have a service app that creates AppDomain's during the course of its use for long running tasks. I've been tracking these by storing them in a Hashtable with a unique ID. After a task is completed the service app then unloads the AppDomain allocated to that task and then it's removed it from the appdomain Hashtable. Purely from a san...

What's the difference between AppDomain.CurrentDomain.BaseDirectory and Application.ExecutablePath in practice?

According to the MSDN, the BaseDirectory is where an AppDomain will look for DLLs to load, while ExecutablePath will provide the path to the original executable file (including file name). I know that one has the file name and the other does not. I know that if I create a new AppDomain I can give it a different path. But removing the ...

Executing and then Deleting a DLL in c#

I'm creating a self updating app where I have the majority of the code in a seperate DLL. It's command line and will eventually be run on Mono. I'm just trying to get this code to work in C# on windows at the command line. How can I create a c# application that I can delete a supporting dll while its running? AppDomain domain = AppDoma...

Can I inject a thread in a remote app domain from C#

I was wondering if its possible to inject a thread into a remote app domain running in a separate process. My guess is that I could do this using the debugging interfaces (ICorDebug) but I was wondering if there is any other way? ...

How to force a MSTEST TestMethod to reset all singletons/statics before running?

I'm using MSTEST inside Visual Studio 2008. How can I have each unit test method in a certain test class act as if it were the first test to run so that all global state is reset before running each test? I do not want to explicitly clean up the world using TestInitialize, ClassInitialize, AssemblyInitialize, etc. For example: [TestClas...

Counting instances of a class in the AppDomain

I wonder if there is a way to either programatically or using a third party tool (profiler?) get an overview of how many instances of a class are currently active in the AppDomain (including or excluding derived classes), and even better, where they are allocated (not sure if that is even possible). I know that I could change my own cla...

Are all pages within an ASP.Net application ran in the same appdomain?

I understand that requests are served by different threads, but do they all come from the same appdomain, too? ...

How to load a .NET assembly for reflection operations and subsequently unload it?

I'm writing a tool to report information about .NET applications deployed across environments and regions within my client's systems. I'd like to read the values of assembly attributes in these assemblies. This can be achieved using Assembly.ReflectionOnlyLoad, however even this approach keeps the assembly loaded. The issue here is th...

Handling uncaught exceptions in C# console application

Hi all! I'm currently writing server that hosts several modules. Server runs each module in separate AppDomain. What I want to achieve is exception isolation. I mean when one module throws exception I don't want whole process to terminate, just this specific AppDomain. I know that I can tell CLR to fallback to old behaviour (.NET 1.0) wh...

App Domain per User Session in IIS

Hello, This question is about App domains and Sessions. Is it possible to have IIS run each User Session in a seperate App Domain. If Yes, Could you please let me settings in the config file that affect this. Regards, Anil. ...

What is the scope of finalizer thread - per application domain or per process?

Based on all my reading there should be one GC thread to invoke all finalizers. Now, the question is what is the scope of this "one" thread - per process or per application domain, as the whole intention of domains is to separate and make "independent" different applications in one process space. I read here: If an unhandled excepti...

Does COM interop respect .NET AppDomain boundaries for assembly loading?

Here's the core problem: I have a .NET application that is using COM interop in a separate AppDomain. The COM stuff seems to be loading assemblies back into the default domain, rather than the AppDomain from which the COM stuff is being called. What I want to know is: is this expected behaviour, or am I doing something wrong to cause th...

Activator.GetObject - MarshalByRefObject

In .Net Activator.GetObject(Type type, string url, object data) returns a proxy to the object. I guess that proxy inherits from MarshalByRefObject and can be sent across AppDomains. Am I right? In my app, I am creating an object in appdomain A and using it appdomain B. The object's members are proxyobjects created using Activator.GetObj...

How to use an AppDomain to limit a static class' scope for thread-safe use?

Howdy, I have been bitten by a poorly architected solution. It is not thread safe! I have several shared classes and members in the solution, and during development all was cool... BizTalk has sunk my battle ship. We are using a custom BizTalk Adapter to call my assemblies. The Adapter is calling my code and running things in ...

How best to communicate between AppDomains?

I have an application that needs to send a moderately high volume of messages between a number of AppDomains. I know that I could implement this using remoting, but I have also noticed that there are cross-domain delegates. Has anyone looked at this kind of problem? ...

Does Silverlight use a separate application domain for each browser tab?

If the same Silverlight application is running in two web browser tabs, does each tab use a separate application domain? If you know where Microsoft explicitly provides this information, please include a reference. ...