Note that there are some explanatory texts on larger screens.

plurals
  1. POException caused by AppDomain when it shouldn't?
    primarykey
    data
    text
    <p>I am working on my MCTS and currently studying the AppDomain functionality. But I am running into something unclear. <code>AppDomain</code> should be capturing <code>Exception</code> and allow the domain to safely unload. (With the possible exception of the <code>StackOverflowException</code> as suggested elsewhere)</p> <pre><code>AppDomainSetup setup = new AppDomainSetup(); setup.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory; Evidence adevidence = AppDomain.CurrentDomain.Evidence; domain.UnhandledException += new UnhandledExceptionEventHandler(domain_UnhandledException); AppDomain domain = AppDomain.CreateDomain("MyDomain", adevidence, setup); </code></pre> <p>When I decide to create an instance of the example class in an assembly I created for this purpose I should be getting a safe, restricted Domain which will capture errors that occur and can be safely unloaded. At least this is how I understand it from my study book.</p> <pre><code>var type = (IDoSomeWork) domain.CreateInstanceAndUnwrap("Library1", "Library1.Class1"); type.Run(); </code></pre> <p>This throws an exception however on <code>type.Run()</code> (since I made it that way). But shouldn't the <code>AppDomain</code> capture it safely? Isn't that why we have an <code>AppDomain</code>?</p> <p><strong>UPDATE:</strong></p> <p>As requested, I have included the definition of the <code>Library1.Class1</code>. Also, for clarity, the <code>UnhandledExceptionEventHandler</code> has no influence on capturing the exception and isn't relevant to the question.</p> <pre><code>[Serializable] public class Class1 : MarshalByRefObject, IDoSomeWork { public void Run() { Debug.WriteLine(AppDomain.CurrentDomain.FriendlyName); throw new ApplicationException(String.Format("{0}", this.ToString())); } } </code></pre> <p>I have verified that it runs in <code>MyDomain</code>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload