using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using System.Security.Policy; using System.Reflection; using System.Threading; using System.IO; namespace WindowsFormsApplication1 { public class MyClass { public string callBackTest = "CallBackTest"; } static class Program { /// /// アプリケーションのメイン エントリ ポイントです。 /// [STAThread] static void Main() { AppDomainSetup setup = new AppDomainSetup(); setup.ApplicationBase = @"D:\Test"; setup.ConfigurationFile = @"D:\Test\Test.exe.config"; setup.LoaderOptimization = LoaderOptimization.MultiDomainHost; Evidence baseEvidence = AppDomain.CurrentDomain.Evidence; Evidence evidence = new System.Security.Policy.Evidence(baseEvidence); var ap = AppDomain.CreateDomain("TestAppDomain", evidence, setup); var loadedAssembly1 = ap.Load(Assembly.GetEntryAssembly().GetName()); // ダメ? var loadedAssembly2 = ap.Load(File.ReadAllBytes(Application.ExecutablePath)); // ダメ? //ap.SetupInformation.ApplicationBase = @"D:\Test"; // ↓ap.Loadで読み込んだはずなのになぜ?? // ファイルまたはアセンブリ // 'WindowsFormsApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'、 // またはその依存関係の 1 つが読み込めませんでした。指定されたファイルが見つかりません。 ap.DoCallBack(new CrossAppDomainDelegate(() => MessageBox.Show(new MyClass().callBackTest))); ap.ExecuteAssembly(@"D:\Test\Test.exe", new[] { "a", "b", "c", "d" }); var ts = new ThreadStart(()=> ap.ExecuteAssembly(@"D:\Test\Test.exe", new[]{"a","b", "c", "d"})); var th = new Thread(ts); th.SetApartmentState(ApartmentState.STA); th.Start(); } } }