I've seen this Topic : Creating an instance from a class name
and written this code:
public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { object obj = Activator.CreateInstance(null, "MyClass"); MyClass t = (MyClass)obj; t.My1 = 100; MessageBox.Show(t.My1.ToString()); } } public class MyClass { public int My1 { get; set; } public int My2 { get; set; } } However when its runs there's an exception:
Could not load type 'MyClass' from assembly 'Test_Reflection, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. I have another question. I have a class in one assembly that has some property. In another assembly I want create instance of it and get access to it's properties, by typing one of them just using stringy Class Name. How can I do that?