Cross AppDomain Exception Handling. Plugin architecture. [modified]
-
Hi all, I want to handle a unhandled exception thrown by a plugin running in its own appDomain (ie not Defualt appDomain) in defualt appDomain (host appliation), and then unload the culprit appDomain.. Is it really possible to handle this kind of cross appDomain exception. the exception may occur any time during the life time of plugin appdomain ( say some buttton in the plugin throws some unhandled exception..) please have a look on the sample code given below.. What should i do handle the exception thrown by button1.. I never want to close my host application at any cost. it should continue its execution whatever happens in plugins.. please give me guide lines. //********************* Plug in ******************************* public class BadPlugin: Form,IPlugin { private System.Windows.Forms.Button button1; public StaffList() { InitializeComponent(); } private void InitializeComponent() { this.textBox1 = new System.Windows.Forms.TextBox(); this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(232, 96); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(176, 48); this.button1.TabIndex = 1; this.button1.Text = "button1"; this.button1.Click += new System.EventHandler(this.button1_Click); // // StaffList // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(488, 302); this.Controls.Add(this.button1); this.Controls.Add(this.textBox1); this.Name = "StaffList"; this.ResumeLayout(false); } private void button1_Click(object sender, System.EventArgs e) { throw new Exception("Bad plgin exploded exception"); } } //********************* Plug in Interface ******************************* public interface IPlugin { void Show(); } //******************** Plug in Host Application*************************** try { AppDomain app = AppDomain.CreateDomain("PluginDomain"); IPlugin plugin = (IPlugin)app.CreateInstanceAndUnwrap("SamplePlugins","SamplePlugins.BadPlugin"); plugin.Show(); } catch(Exception ex) { MessageBox.Show(ex.Message); } Thanks and regards 123developer -- modified at 1:06 Tuesday 10th July, 2007
-
Hi all, I want to handle a unhandled exception thrown by a plugin running in its own appDomain (ie not Defualt appDomain) in defualt appDomain (host appliation), and then unload the culprit appDomain.. Is it really possible to handle this kind of cross appDomain exception. the exception may occur any time during the life time of plugin appdomain ( say some buttton in the plugin throws some unhandled exception..) please have a look on the sample code given below.. What should i do handle the exception thrown by button1.. I never want to close my host application at any cost. it should continue its execution whatever happens in plugins.. please give me guide lines. //********************* Plug in ******************************* public class BadPlugin: Form,IPlugin { private System.Windows.Forms.Button button1; public StaffList() { InitializeComponent(); } private void InitializeComponent() { this.textBox1 = new System.Windows.Forms.TextBox(); this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(232, 96); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(176, 48); this.button1.TabIndex = 1; this.button1.Text = "button1"; this.button1.Click += new System.EventHandler(this.button1_Click); // // StaffList // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(488, 302); this.Controls.Add(this.button1); this.Controls.Add(this.textBox1); this.Name = "StaffList"; this.ResumeLayout(false); } private void button1_Click(object sender, System.EventArgs e) { throw new Exception("Bad plgin exploded exception"); } } //********************* Plug in Interface ******************************* public interface IPlugin { void Show(); } //******************** Plug in Host Application*************************** try { AppDomain app = AppDomain.CreateDomain("PluginDomain"); IPlugin plugin = (IPlugin)app.CreateInstanceAndUnwrap("SamplePlugins","SamplePlugins.BadPlugin"); plugin.Show(); } catch(Exception ex) { MessageBox.Show(ex.Message); } Thanks and regards 123developer -- modified at 1:06 Tuesday 10th July, 2007
-
Bothered to check out the AppDomain members list? http://msdn2.microsoft.com/en-us/library/system.appdomain_members.aspx[^]
Dude, I already had a look on AppDomain members.. if u r pointing to AppDomain.UnhandledException event.. , it is not firing in my case. I have registered this event bfore Application.Run().. in defualt appDomain.. According to MSDN documents, it sholud be fired before the application going to unstable state.. But in my case i am getting the unhanled exception message runtime messagebox.. What i am really missing my code. can you point the specific member you are suggesting. Thanks and regards 123developer
-
Bothered to check out the AppDomain members list? http://msdn2.microsoft.com/en-us/library/system.appdomain_members.aspx[^]
i didn't get it.. could u please explain that which appDomain member should i concentrate on?