Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
As per documentatio at msdn "Faults in one application domain cannot affect other code running in another application domain.

Main Program:

C#
System.AppDomain myDomain = System.AppDomain.CreateDomain("MyDomain");

             myDomain.ExecuteAssembly(@"C:\Users\delllaptop\Documents\Visual Studio 2012\Projects\AppDomain\HelloWorld\bin\Debug\HelloWorld.exe");


HelloWorld Code:

C#
string abc = "abc";
                int i = Convert.ToInt16(abc);


But in my case, when i run main program and loading and executing helloworld.exe (which generating exception), is affecting main program to crash.
Posted
Updated 15-Jul-13 9:39am
v2

1 solution

First of all, "cannot affect other code running in another application domain" is a certain exaggeration, or a figure of speech. It simply means that their address spaces are strictly isolated, like in the case of separate processes. You should not understand it literally. Application Domains can communicate via IPC, and there are additional simplified IPC-like methods defined specially for Application Domain. One example is System.AppDomain.SetData/GetData. My point is: if, for example, Application Domains exchange messages, and one message says "kill yourself", and if some Application Domain is programmed to kill itself in response to such message, will you call it "affecting"? :-)

Your case is different though. First of all, you should pay attention for the fact: your myDomain.ExecuteAssembly method is executed not in the domain you called "MyDomain". It is executed in the domain which created that new domain. And the side effect of this call is the execution of "HelloWord.exe" in the domain "MyDomain".

Now, you should understand that the domains are only isolated in address spaces. The code and call stack are shared. In particular, it means that if some exception is thrown in one Application Domain, it will be propagated to another one with the code upper on stack. This is what happens. And this is very good, not bad.

If you had a separate thread, it would be different: the exception would propagate to the top of the thread but not affect the parent thread. You can freely combine threads and Application Domains: execute one or more threads in one Application Domain, or same thread in different Application Domains.
In connection to threading, pay attention:
MSDN tells us:
This method does not create a new process or application domain, and it does not execute the entry point method on a new thread.
I can tell you what it really does: it loads the said assembly in the same process of the said Domain, tries to find the entry point method (normally, the Main method) and, if found, just calls it in the current threads, the same thread as the one calling AppDomain.ExecuteAssembly. This way, the application assembly is not really used as the application. With .NET, this is normal: there is no a fundamental difference between "EXE" and "DLL", in this case, your "EXE" is used as a kind of a plug-in "DLL".

And finally, you should not call this a "crash". For software developers, there is no such thing as "crash", but there are exception, in particular, those forgotten to be ever caught, up to the top of each thread.

—SA
 
Share this answer
 
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900