I have have an application which consists of an windows form project and a class library project. When it starts the executable sets a static value in the dll.
using MyClassLibrary;
namespace MyExeApplication
{
public partial class MainForm : Form
{
Hashtable ht = null;
void Form_Load(...)
{
ht = new Hashtable();
ht.add("1", "Open");
ht.add("2", "Close");
Calculate.BasicValues = ht;
}
public Hashtable GetBasicValues()
{
return ht;
}
}
}
namespace MyClassLibrary
{
public class Calculate()
{
public static Hashtable BasicValues {get; set;}
}
}
Now suppose the application is running in memory (the executable). My purpose is to create another standalone application and use the value BasicValues in the function Calculate in the class library.
using MyClassLibrary;
namespace TestApplication
{
public partial class MainForm : Form
{
private void TestValueFromDll()
{
System.Windows.Forms.MessageBox.Show("Values of Hashtable");
Hashtable ht = Calculate.BasicValues;
//The hashtable is null and values are not there
//The above will not work. Could I say something like
//Get the running instance of MyExeApplication
//and invoke GetBasicValues() ?
}
}
}
I guess it does not work because my TestApplication has copied the MyClassLibrary.dll to the bin folder where the executable TestApplication.exe is located. Thus a different dll was used (not the dll that was used by the first application MyExeApplication).
And my question is how can I solve this problem? Is it possible to use reflection and Get the instance of MyExeApplication and read the values from there? Is there any other way?
Thank you