I have 2 windowsForm projects (Project A and B) in C #, but I would like to add in Project B the reference to Project A by code and call Project A from within Project B. I used Assembly.Load and it is only working if I remove the Main void arguments.
The form of Project A should be open as MdiParent of Project B.
I tried using Assembly.load and activator.createinstance but it didn't work when I try to pass the method parameter.
With param args is returning an error (System.MissingMethodException: 'Constructor in type' CompareXMLTools.Main 'not found.')
#using System.Reflection.Assembly
Project A Program.cs
namespace CompareXMLTools
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Main(args));
}
}
}
WindowsForm
namespace CompareXMLTools
{
public partial class Main : Form
{
public Main(string[] args)
{
InitializeComponent();
ArgsPassed = args;
}
}
}
Project B
namespace XMLValidator
{
public partial class frmMain : Form
{
public frmMain(string[] args)
{
InitializeComponent();
ArgsPassed = args;
}
}
private void tsbrnCompareXML_Click(object sender, EventArgs e)
{
object dllUserControl = null;
System.Reflection.Assembly assembly2 = AppDomain.CurrentDomain.Load(File.ReadAllBytes(@"D:\Projetos C#\XMLValidator\XMLValidator\CompareXMLTools.exe"));
dllUserControl = assembly2.CreateInstance("CompareXMLTools.Main", true, System.Reflection.BindingFlags.Default, null, new string[] { }, System.Globalization.CultureInfo.CurrentCulture, null);
((frmMain)dllUserControl).MdiParent = this;
((frmMain)dllUserControl).Show();
}
}
Note: The Project B command only works if I remove the ** string [] args
** field from the Main Method.
I need to pass arguments when call the new WinForm of project A, how can I do this?