[Mono-list] AppDomain problems

Gonzalo Paniagua Javier gonzalo@ximian.com
15 Aug 2002 03:16:20 +0200


El mié, 14-08-2002 a las 19:39, Dietmar Maurer escribió:
> I cant get the attached program to work on MS windows, even if security
> is turned off with: CasPol -s off

I made it work without disabling security.

> ------------------------------------------------------------------------
> using System;

using System.IO;

> using System.Security.Policy;
> using System.Threading;
> using System.Runtime.Serialization;
> 
> class Container {
> 
> 	[Serializable]
> 	public struct c2 : ISerializable {
> 		public int a;
> 		public string s1;
> 
> 		private c2 (SerializationInfo info, StreamingContext context) {
> 			a = info.GetInt32("a");
> 			s1 = info.GetString("s1");
> 			Console.WriteLine ("SetObjectData called: " + info.AssemblyName + "," +
> 					   info.FullTypeName + " " + s1 + ", " + a);
> 		}
> 
> 		public void GetObjectData (SerializationInfo info, StreamingContext context) {
> 			Console.WriteLine ("GetObjectData called: " + info.AssemblyName + "," +
> 					   info.FullTypeName + " " + s1 + ", " + a);
> 			info.AddValue ("a", a);
> 			if (s1 != null)
> 				info.AddValue ("s1", s1);
> 			else
> 				info.AddValue ("s1", "(null)");
> 		}
> 	}
> 	
> 	[Serializable]
> 	public class c1 {
> 		public c1 () {
> 			e1.a = 3;
> 			e1.s1 = "SS";
> 		}
> 		public int a = 1;
> 		public int b = 2;
> 		public string s1 = "TEST1";
> 		[NonSerialized] public string s2 = "TEST2";
> 		public c2 [] sa = new c2 [2];
> 		public c2 e1;
> 	}
> 	
> 	static int Main ()
> 	{
> 		AppDomainSetup setup = new AppDomainSetup ();
> 		setup.ApplicationBase = ".";

Changed to: setup.ApplicationBase = Directory.GetCurrentDirectory ();
> 
> 		Console.WriteLine (AppDomain.CurrentDomain.FriendlyName);
> 			
> 		AppDomain newDomain = AppDomain.CreateDomain ("NewDomain", new Evidence (), setup);

As Jaak pointed out, it would better to use: 

	new Evidence (AppDomain.CurrentDomain.Evidence);

as the second argument to CreateDomain, but it does not affect to the
behavior of the program (it also works with null as Evidence).

And that's all.

Of course, don't ask me why using the full path works and "." does not
;-).

- Gonzalo