kippthekidd

AppDomain switch bug in Mono

Feb 23rd, 2012
93
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using System.Diagnostics;
  4.  
  5. class Program
  6. {
  7.     [DllImport("test.dll")]
  8.     static extern void WireCallback(Action func); // This saves the func in unmanaged space.
  9.     [DllImport("test.dll")]
  10.     static extern void DoCallback(); // This calls the saved func.
  11.  
  12.     static Action callback;
  13.  
  14.     static void Main()
  15.     {
  16.         callback = () => { };
  17.         WireCallback(callback);
  18.  
  19.         AppDomain ad = AppDomain.CreateDomain("foo");
  20.         ad.DoCallBack(new CrossAppDomainDelegate(OtherDomainTest));
  21.     }
  22.  
  23.     static void OtherDomainTest()
  24.     {
  25.         int appDomainId = AppDomain.CurrentDomain.Id;
  26.         DoCallback();
  27.         Console.WriteLine("appDomainId == AppDomain.CurrentDomain.Id = {0}", appDomainId == AppDomain.CurrentDomain.Id);
  28.         Debug.Assert(appDomainId == AppDomain.CurrentDomain.Id);
  29.     }
  30. }
RAW Paste Data