How can I access an executable instance of a standalone .NET executable from a .NET Dll or Exe?
I have an application that consists of a window form project and a class library project. When it runs, 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 let's assume the application is running in memory (executable). My goal is to create another standalone application and use the BasicValues in the Calculate function 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 think it won't work because my TestApplication copied MyClassLibrary.dll to the bin folder where the TestApplication.exe executable is located. So another dll was used (not the dll that was used by the first MyExeApplication).
And my question is, how can I solve this problem? Is it possible to use reflection and get an instance of MyExeApplication and read values from there? Is there another way?
thanks
It's not about where the DLL is located. It looks like the real problem is that the DLL is being loaded into the "MyExeApplication" application and you need to access from the "TestApplication" application. And as it turned out, .NET Remoting was meant for communicating data between applications. There is information on this on MSDN .
a source to share
If you create TestApplication, MyExeApplication and MyClassLibrary in the same folder (by setting the output folder in the project properties menu), I would suggest that you can avoid using reflection. Also, I'm curious as to why you need to do something like this? Is BasicValues something that can be replaced with a SQL table or even registry settings?
Good luck!
a source to share
There is no way to do this that I am aware of without being attached to another process as a debugger.
Your best option is to have your first Hashtable app store in some kind of shared space. Either as a file on disk, in a database, with some form of shared memory, or transfer it using remote access.
Which option you want to use will really depend on how the data is used by each application.
a source to share
Thanks everyone for the answers. I am currently using the registry as a temporary storage for storing values. I will read about Remote Access Domains and Applications and try to do this.
The reason I want is because I have an exe application running in the background (reduced to a window pane). This exe application acts as a central API and generates some login information that should be accessible from any test program using MyClassLibrary.dll.
Would it be nice if I put all the code from my dll class into an exe and then only have one executable that has everything?
Then in MyTestApplication I could add a link to the exe. But I would have the same problem. Because if I want to create another application that integrates with the exe API eg. MyTestApplication2 and add a link to the exe, will I have the same problem?
I think this is impossible from reflection. However, in VB6 you could say something like o = GetObject (, "MyExeApplication.Class") and then I could say o.GetBasicValues ()).