回答編集履歴

2

修正

2019/06/17 01:58

投稿

Zuishin
Zuishin

スコア28673

test CHANGED
@@ -22,7 +22,7 @@
22
22
 
23
23
 
24
24
 
25
- namespace ConsoleApp2
25
+ namespace ConsoleApp3
26
26
 
27
27
  {
28
28
 
@@ -34,13 +34,9 @@
34
34
 
35
35
  {
36
36
 
37
- Assembly
37
+ var assembly = Assembly.Load("ConsoleApp1");
38
38
 
39
- .Load("ConsoleApp1")
40
-
41
- .EntryPoint
42
-
43
- .Invoke(null, new object[] { new string[] { assembly.Location } });
39
+ assembly.EntryPoint.Invoke(null, new object[] { new string[] { assembly.Location } });
44
40
 
45
41
  Console.ReadKey();
46
42
 
@@ -51,3 +47,7 @@
51
47
  }
52
48
 
53
49
  ```
50
+
51
+
52
+
53
+ コードが間違っていたので修正しました。

1

追記

2019/06/17 01:57

投稿

Zuishin
Zuishin

スコア28673

test CHANGED
@@ -3,3 +3,51 @@
3
3
  参照した上で Main メソッドを取得して呼んでみてください。
4
4
 
5
5
  プライベートなメンバーにアクセスするにはリフレクションが必要です。
6
+
7
+
8
+
9
+ # 追記
10
+
11
+
12
+
13
+ ConsoleApp1.exe を ConsoleApp2.exe と同じディレクトリに置き、次のコードを実行することで ConsoleApp1.exe の Main メソッドを呼び出せます。
14
+
15
+
16
+
17
+ ```C#
18
+
19
+ using System;
20
+
21
+ using System.Reflection;
22
+
23
+
24
+
25
+ namespace ConsoleApp2
26
+
27
+ {
28
+
29
+ class Program
30
+
31
+ {
32
+
33
+ static void Main(string[] args)
34
+
35
+ {
36
+
37
+ Assembly
38
+
39
+ .Load("ConsoleApp1")
40
+
41
+ .EntryPoint
42
+
43
+ .Invoke(null, new object[] { new string[] { assembly.Location } });
44
+
45
+ Console.ReadKey();
46
+
47
+ }
48
+
49
+ }
50
+
51
+ }
52
+
53
+ ```