fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Windows.Forms;
  5. using System.Security.Policy;
  6. using System.Reflection;
  7. using System.Threading;
  8. using System.IO;
  9.  
  10. namespace WindowsFormsApplication1
  11. {
  12. public class MyClass
  13. {
  14. public string callBackTest = "CallBackTest";
  15. }
  16. static class Program
  17. {
  18. /// <summary>
  19. /// アプリケーションのメイン エントリ ポイントです。
  20. /// </summary>
  21. [STAThread]
  22. static void Main()
  23. {
  24. AppDomainSetup setup = new AppDomainSetup();
  25. setup.ApplicationBase = @"D:\Test";
  26. setup.ConfigurationFile = @"D:\Test\Test.exe.config";
  27. setup.LoaderOptimization = LoaderOptimization.MultiDomainHost;
  28. Evidence baseEvidence = AppDomain.CurrentDomain.Evidence;
  29. Evidence evidence = new System.Security.Policy.Evidence(baseEvidence);
  30. var ap = AppDomain.CreateDomain("TestAppDomain", evidence, setup);
  31.  
  32. var loadedAssembly1 = ap.Load(Assembly.GetEntryAssembly().GetName()); // ダメ?
  33. var loadedAssembly2 = ap.Load(File.ReadAllBytes(Application.ExecutablePath)); // ダメ?
  34. //ap.SetupInformation.ApplicationBase = @"D:\Test";
  35.  
  36. // ↓ap.Loadで読み込んだはずなのになぜ??
  37. // ファイルまたはアセンブリ
  38. // 'WindowsFormsApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'、
  39. // またはその依存関係の 1 つが読み込めませんでした。指定されたファイルが見つかりません。
  40. ap.DoCallBack(new CrossAppDomainDelegate(() => MessageBox.Show(new MyClass().callBackTest)));
  41.  
  42. ap.ExecuteAssembly(@"D:\Test\Test.exe", new[] { "a", "b", "c", "d" });
  43.  
  44. var ts = new ThreadStart(()=> ap.ExecuteAssembly(@"D:\Test\Test.exe", new[]{"a","b", "c", "d"}));
  45. var th = new Thread(ts);
  46. th.SetApartmentState(ApartmentState.STA);
  47. th.Start();
  48. }
  49.  
  50. }
  51. }
  52.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(4,14): error CS0234: The type or namespace name `Windows' does not exist in the namespace `System'. Are you missing an assembly reference?
Compilation failed: 1 error(s), 0 warnings
stdout
Standard output is empty