[Mono-bugs] [Bug 53788][Nor] New - AppDomainSetup.PrivateBinPath bug in Mono 0.30

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Tue, 3 Feb 2004 05:25:03 -0500 (EST)


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 vguzev@yandex.ru.

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

--- shadow/53788	2004-02-03 05:25:03.000000000 -0500
+++ shadow/53788.tmp.29908	2004-02-03 05:25:03.000000000 -0500
@@ -0,0 +1,275 @@
+Bug#: 53788
+Product: Mono/Class Libraries
+Version: unspecified
+OS: Red Hat 7.3
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: System
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: vguzev@yandex.ru               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: AppDomainSetup.PrivateBinPath bug in Mono 0.30
+
+Description of Problem:
+The example attached works fine on Mono 0.28 and 0.29, but no longer works
+in Mono-0.30.
+
+Steps to reproduce the problem:
+1. Save the attachments (at the end of the report) to the folder /path/
+2. Change the variable 'folder' in file '/path/pinvokecomplex/amcsharp.cs'
+in class AppDomainController in method Test to actual location '/path/'
+3. Compile the sources:
+   cd /path/pinvokecomplex/
+   mcs /t:library amcsharp.cs
+   mcs /r:amcsharp.dll TestPInvoke.cs
+   cp amcsharp.dll ../Temp/
+   mcs /r:amcsharp.dll ../Temp/Test.cs
+4. Run the first part of the program
+   cd /path/Temp/
+This will create the file '/path/Temp/serializedobject.txt' with serialized
+object saved inside.
+5. Run the second part of the program
+   cd /path/pinvokecomplex/; mono TestPInvoke.exe
+
+This program will deserialize object from txt-file and try to launch some
+method of this object.
+
+Actual Results:
+This will throw the following exception:
+8<----------------------------------------------------------
+3:System.IO.FileNotFoundException: File 'Test, Version=0.0.0.0,
+Culture=neutral, PublicKeyToken=null' not found.
+in (unmanaged)
+/local/users_shared/vadim/mono/mono-0.30-1.20040129/lib/libmono.so.0
+(mono_ra
+ise_exception+0x1f) [0x4008b74f]
+in (unmanaged)
+/local/users_shared/vadim/mono/mono-0.30-1.20040129/lib/libmono.so.0
+[0x400b1256]
+in <0x0006c> (wrapper remoting-invoke-with-check)
+System.AppDomain:LoadAssembly (string,System.Security.Policy.Evidence)
+in <0x0006b> System.AppDomain:Load (string)
+in <0x00058> (wrapper remoting-invoke-with-check) System.AppDomain:Load
+(string)
+in <0x0001c> System.Reflection.Assembly:Load (string)
+in <0x00077>
+System.Runtime.Serialization.Formatters.Binary.ObjectReader:GetDeserializat
+i
+onType (long,string)
+in <0x0024b>
+System.Runtime.Serialization.Formatters.Binary.ObjectReader:ReadTypeMetadat
+a
+(System.IO.BinaryReader,bool)
+in <0x00048>
+System.Runtime.Serialization.Formatters.Binary.ObjectReader:ReadObjectInsta
+n
+ce
+(System.IO.BinaryReader,bool,long&,object&,System.Runtime.Serialization.Ser
+i
+alizationInfo&)
+in <0x00095>
+System.Runtime.Serialization.Formatters.Binary.ObjectReader:ReadObject
+(System.Runtime.Serialization.Formatters.Binary.BinaryElement,System.IO.Bin
+a
+ryReader,long&,object&,System.Runtime.Serialization.SerializationInfo&)
+in <0x00086>
+System.Runtime.Serialization.Formatters.Binary.ObjectReader:ReadNextObject
+(System.IO.BinaryReader)
+in <0x000b6>
+System.Runtime.Serialization.Formatters.Binary.ObjectReader:ReadObjectGraph
+(System.IO.BinaryReader,bool,object&,System.Runtime.Remoting.Messaging.Head
+e
+r[]&)
+in <0x001b0>
+System.Runtime.Serialization.Formatters.Binary.BinaryFormatter:Deserialize
+(System.IO.Stream,System.Runtime.Remoting.Messaging.HeaderHandler)
+in <0x00019>
+System.Runtime.Serialization.Formatters.Binary.BinaryFormatter:Deserialize
+(System.IO.Stream)
+in <0x00093> aMCSharp.AppDomainProcessor:CallMethod (string)
+8<----------------------------------------------------------
+
+
+Expected Results:
+8<----------------------------------------------------------
+object after deserialization:
+(ObjectHolder
+ .assemblyName=Test
+ .className=A
+ .methodName=fun1
+ .parameters=World!
+ .object=(some string:111)
+)
+-------------------------------------Hello, World!-------------------------
+----------
+(some string:111)
+8<----------------------------------------------------------
+
+
+How often does this happen? 
+Always
+
+Additional Information:
+
+It seems to me that this bug is connected with the 
+AppDomainSetup.PrivateBinPath variable.
+When deserializing some object mono doesn't check for assemblies in
+PrivateBinPath. Although it can check now only relative paths...
+
+I can send the full example with Makefile (I didn't find how to attach a 
+zip-file here... :-( )
+
+Attachment:
+______________________________________________________
+1. /path/pinvokecomplex/amcsharp.cs:
+______________________________________________________
+using System;
+using System.IO;
+using System.Reflection;
+using System.Runtime.Serialization;
+using System.Runtime.Serialization.Formatters.Binary;
+
+namespace aMCSharp {
+ [Serializable()]
+ public class ObjectHolder {
+  public string assemblyName;
+  public string className;
+  public string methodName;
+  public object parameters;
+  public object serializedObject;
+
+  public ObjectHolder( string assemblyName, string className, string 
+methodName,
+   object parameters, object serializedObject ) {
+   this.assemblyName = assemblyName;
+   this.className = className;
+   this.methodName = methodName;
+   this.parameters = parameters;
+   this.serializedObject = serializedObject;
+  }
+
+  public override string ToString() {
+   return "(ObjectHolder\n" +
+    " .assemblyName=" + assemblyName + "\n" +
+    " .className=" + className + "\n" +
+    " .methodName=" + methodName + "\n" +
+    " .parameters=" + parameters + "\n" +
+    " .object=" + serializedObject.ToString() + "\n)";
+  }
+ }
+
+ public class AppDomainController {
+  public static AppDomain appDomain;
+  public static AppDomainProcessor processor;
+
+  public static void Test() {
+   string folder = "/home/vadim/archive/pinvokeandserialization/";
+   AppDomainSetup setup = new AppDomainSetup();
+   setup.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;
+   setup.PrivateBinPath = folder + "Temp/";
+   setup.ApplicationName = "1";
+   setup.ShadowCopyFiles = "true";
+   try {
+    appDomain = AppDomain.CreateDomain( "1", null, setup );
+    processor = (AppDomainProcessor)
+      appDomain.CreateInstanceFromAndUnwrap(
+      "amcsharp.dll",
+      "aMCSharp.AppDomainProcessor" );
+
+    processor.CallMethod( folder + "Temp/serializedobject.txt" );
+   }
+   catch ( Exception e ) {
+    Console.WriteLine( "1:" + e );
+   }
+  }
+ }
+
+ public class AppDomainProcessor : MarshalByRefObject {
+  public void CallMethod( string fileName ) {
+   try {
+    FileStream fs = new FileStream( fileName, FileMode.Open, 
+FileAccess.Read );
+    ObjectHolder oh = (ObjectHolder) new BinaryFormatter().Deserialize( 
+fs );
+    Console.WriteLine( "object after deserialization: \n" + oh );
+    fs.Close();
+
+    Assembly assembly = AppDomain.CurrentDomain.Load( oh.assemblyName );
+    Type type = assembly.GetType( oh.className );
+    MethodInfo method = type.GetMethod( oh.methodName );
+    method.Invoke( oh.serializedObject, new object[] { oh.parameters } );
+   }
+   catch ( Exception e ) {
+    Console.WriteLine( "3:" + e );
+   }
+  }
+ }
+}
+______________________________________________________
+
+______________________________________________________
+2. /path/pinvokecomplex/amcsharp.cs:
+______________________________________________________
+using System;
+using aMCSharp;
+
+public class TestPInvoke {
+ public static void Main( string[] args ) {
+  AppDomainController.Test();
+ }
+}
+______________________________________________________
+
+______________________________________________________
+3. /path/Temp/Test.cs:
+______________________________________________________
+
+using System;
+using System.Runtime.Serialization;
+using aMCSharp;
+using System.Runtime.Serialization.Formatters.Binary;
+using System.IO;
+
+[Serializable()]
+public class A {
+ public string x = "";
+ public int y = 2;
+ public A( string x, int y ) {
+  this.x = x;
+  this.y = y;
+ }
+
+ public void fun1( string line ) {
+  Console.WriteLine( "-------------------------------------Hello, " + line 
++ "-----------------------------------" );
+  Console.WriteLine( this );
+ }
+
+ public override string ToString() {
+  return "(" + x + ":" + y + ")";
+ }
+}
+
+[Serializable()]
+public class Test {
+
+ public static void Main( string[] args ) {
+  A a = new A( "some string", 111 );
+  Console.WriteLine( "A before: " + a );
+  ObjectHolder oh = new ObjectHolder( "Test", "A", "fun1", "World!", a );
+  Console.WriteLine( oh );
+
+  BinaryFormatter bf = new BinaryFormatter();
+  FileStream fs = new FileStream( "serializedobject.txt", 
+FileMode.OpenOrCreate, FileAccess.Write );
+  bf.Serialize( fs, oh );
+  fs.Close();
+ }
+}
+______________________________________________________