[Mono-bugs] [Bug 65903][Wis] New - appdomains assembly resolution is being leaked to other appdomains

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Mon, 13 Sep 2004 17:03:05 -0400 (EDT)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by ddulai@bloomberg.net.

http://bugzilla.ximian.com/show_bug.cgi?id=65903

--- shadow/65903	2004-09-13 17:03:05.000000000 -0400
+++ shadow/65903.tmp.9502	2004-09-13 17:03:05.000000000 -0400
@@ -0,0 +1,107 @@
+Bug#: 65903
+Product: Mono: Class Libraries
+Version: unspecified
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: System
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: ddulai@bloomberg.net               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: appdomains assembly resolution is being leaked to other appdomains
+
+the below code is a demonstration of most of the bug. what it is doing is 
+the following:
+
+1) create appdomain1, and create an instance of BB.Test. it attempts to 
+load the "libd" assembly, and the assemblyresolver knows how to do this.
+
+2) create appdomain2 and do the exact same thing as above, but load the 
+BB.Test from a different assembly. the problem is that the assembly is 
+getting loaded improperly and the second time, the resolving doesnt fire, 
+and the second BB.Test is created from the first assembly!
+
+now, i thought it was maybe because libd is somehow getting loaded and 
+cached globally. so i changed the CreateInstance() to use "foo" instead 
+of "libd", and in this case, it calls the resolving the second time, but i 
+get this trace:
+
+free(): invalid pointer 0x846fc60!
+free(): invalid pointer 0x846fa40!
+free(): invalid pointer 0x8470040!
+free(): invalid pointer 0x8470440!
+
+from AppDomain::Load(byte[])
+
+also, the BB.Test it ends up creating is still from the first assembly.
+
+let me know if you need a test suite that contains all the relevant files
+
+I am using mono-1.0
+
+
+
+using System;
+using System.IO;
+using System.Text;
+using System.Reflection;
+using System.Xml;
+using System.Runtime.Remoting;
+
+namespace BB {
+    public class AppContainerDispatcher {
+        static byte[] loadFile(string filename) {
+            FileStream fs = File.OpenRead(filename);
+            byte[] buffer = new byte[fs.Length];
+            fs.Read(buffer, 0, buffer.Length);
+            fs.Close();
+            return buffer;
+        }
+
+        AppDomain _appdomain;
+        ObjectHandle _t1;
+
+        public AppContainerDispatcher(string lib) {
+            Console.WriteLine("AppContainerDispatcher::Constructor : 
+domain is
+                              " + AppDomain.CurrentDomain);
+            _appdomain = AppDomain.CreateDomain("mydomain-" + lib);
+            _appdomain.AssemblyResolve += new ResolveEventHandler
+(MyResolver);
+            _t1 = _appdomain.CreateInstance("libd", "BB.Test");
+        }
+        public static Assembly MyResolver(object sender, ResolveEventArgs 
+args) {
+            Console.WriteLine("--[ resolver ]--------------------------");
+            Console.WriteLine("MyResolver : " + args.Name);
+            AppDomain domain = (AppDomain) sender;
+
+            string a = AppDomain.CurrentDomain.FriendlyName;
+            int i = a.IndexOf("-")+1;
+            a = a.Substring(i, a.Length-i);
+            Console.WriteLine("loading assembly : " + a);
+            // Once the files are generated, this call is
+            // actually no longer necessary.
+            Assembly assembly = domain.Load(loadFile(a));
+
+            Console.WriteLine("--[ end resolver ]------------------------
+\n\n");
+            return assembly;
+        }
+    }
+};
+
+class App {
+    static void Main(string[] args) {
+        BB.AppContainerDispatcher disp =
+            new BB.AppContainerDispatcher("l/Debug/libd.dll");
+        BB.AppContainerDispatcher disp2 =
+            new BB.AppContainerDispatcher("l/Debug/lib2d.dll");
+    }
+};