Search code examples
c#runtime.net-2.0

Pass object from one dll to another on the runtime


I have 2 projects, in one project I have one form and class with different information, this information is acquiring only during runtime, now in another project I have another form, that will use the object of the first class to get the information and to put it inside form.

Basically I did some research and tried using Reflection for that, but all of the examples I found didn't work properly (actually didn't work at all).

        Assembly a = Assembly.LoadFile("Server.GUI.LocalGUI.dll");
        object o = a.CreateInstance("ServerManager");
        Type t = o.GetType();

this is the code that I tried, not sure if it's correct...

I am using .net 2.0

Is anyone have working example of how to use data of one object in another dll on the runtime?


Solution

  • I have 2 projects : MyForm1 and MyForm2. Take reference of project MyForm1 in MyForm2. Fill MyForm1. Create a instance of the MyForm1 in MyForm2 and access the method and its value.

    Or create another Library project. Expose a static variable in it. Take reference of this library in both the Forms projects. Assign some value from MyForm1 and access the same property in MyForm2.

    But if you really want your code to be a managed code, try learning and implementing MVP. It may give you a new way to look at solutions for your problems.

    You can even create both forms in same project. Process the data in a separate library.