473,769 Members | 1,805 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamic Assemblies and Forms

Hi,

I'm trying to create a Windows Forms portal application and need some help.
What I currently have is a main application (.exe) containing an MDI form.
The idea is that this main application loads forms from packages (i.e. DLLs
containing one or more forms). The trick is that I'd like the form packages
and forms loaded to be dynamic. Therefore the main application should be
able to "discover" all the form packages, then allow those discovered forms
to be "shown" as MdiChildren. New forms should be able to be added and
discovered without ever having to recompile the main application. I know I
need to use dynamically loaded assemblies, but I'm not sure how and where to
start.

How would I go about doing this?

Thank you all for your help!

Sincerely,

Jon
Nov 16 '05 #1
6 1227
JonS. wrote:
Hi,

I'm trying to create a Windows Forms portal application and need some help.
What I currently have is a main application (.exe) containing an MDI form.
The idea is that this main application loads forms from packages (i.e. DLLs
containing one or more forms). The trick is that I'd like the form packages
and forms loaded to be dynamic. Therefore the main application should be
able to "discover" all the form packages, then allow those discovered forms
to be "shown" as MdiChildren. New forms should be able to be added and
discovered without ever having to recompile the main application. I know I
need to use dynamically loaded assemblies, but I'm not sure how and where to
start.

How would I go about doing this?


Hi Jon,

I don't have neither VS or a manual at hand right now, so i will not give you a ready example now.
But check "Assembly" class, it should have a method "LoadAssembly(< DllFileName>)", which will return
an "Assembly" object associated with the dll. Then using Reflection, you can "extract" classes from the loaded asembly.

I will try to post something as i get to the office

Andrey
Nov 16 '05 #2
MuZZy wrote:
JonS. wrote:
Hi,

I'm trying to create a Windows Forms portal application and need some
help. What I currently have is a main application (.exe) containing
an MDI form. The idea is that this main application loads forms from
packages (i.e. DLLs containing one or more forms). The trick is that
I'd like the form packages and forms loaded to be dynamic. Therefore
the main application should be able to "discover" all the form
packages, then allow those discovered forms to be "shown" as
MdiChildren. New forms should be able to be added and discovered
without ever having to recompile the main application. I know I need
to use dynamically loaded assemblies, but I'm not sure how and where
to start.

How would I go about doing this?

Hi Jon,

I don't have neither VS or a manual at hand right now, so i will not
give you a ready example now.
But check "Assembly" class, it should have a method
"LoadAssembly(< DllFileName>)", which will return
an "Assembly" object associated with the dll. Then using Reflection, you
can "extract" classes from the loaded asembly.

I will try to post something as i get to the office

Andrey


Ok, i found a piece of code i used for the task similar to yours - to dynamically load classes from assemblies:
// =============== ======= CODE START =============== =============== ==============

// You shoul add this "using "
using System.Reflecti on;
// Here you load an assembly
private void btnOpenAssembly _Click(object sender, System.EventArg s e)
{
dlgOpen.Filter = "NET Assembly *.dll, *.exe | *.dll; *.exe";
if (dlgOpen.ShowDi alog() != DialogResult.OK ) return;
string fileName = dlgOpen.FileNam e;
// Read
Assembly asm = Assembly.LoadFr om(fileName);
Type[] asm_types = asm.GetTypes();
/*foreach(Type t in mytypes)
{
MethodInfo[] mi = t.GetMethods(fl ags);
Object obj = Activator.Creat eInstance(t);

foreach(MethodI nfo m in mi)
{
m.Invoke(obj, null);
}
}*/
listClasses.Ite ms.Clear();
textMethods.Tex t = "";
foreach(Type t in asm_types)
{
ListViewItem li = new ListViewItem(t. FullName);
li.Tag = t;
listClasses.Ite ms.Add(li);
}
}
//Here you explore it's methods
private void listMethods_Dou bleClick(object sender, System.EventArg s e)
{
if (listClasses.Se lectedItems.Cou nt == 0) return;
ListViewItem li = listClasses.Sel ectedItems[0];
Type t = (Type)li.Tag;
//BindingFlags flags = (BindingFlags.N onPublic | BindingFlags.Pu blic |
// BindingFlags.St atic | BindingFlags.In stance | BindingFlags.De claredOnly);
MethodInfo[] mi = t.GetMethods();
textMethods.Tex t = "";
foreach (MethodInfo m in mi)
{
textMethods.Tex t += ' '+m.Name;
}
}

// =============== ======= CODE END =============== =============== ==============
Code is very amature, but gives you a good start
Hope it helps,
Andrey
Nov 16 '05 #3
Thanks Muzzy,

I'm going to try it out and see what I come up with right now. Since the
object is essentially a form I guess I can use the MdiParent and Show methods
to get it to work dynamically.

What about the whole idea of being able to change/add DLLs (form packages)
while the actual software is running? Is this possible? From what I've read
they say it's doable using different App Domains. Do you know anything about
this?

"MuZZy" wrote:
MuZZy wrote:
JonS. wrote:
Hi,

I'm trying to create a Windows Forms portal application and need some
help. What I currently have is a main application (.exe) containing
an MDI form. The idea is that this main application loads forms from
packages (i.e. DLLs containing one or more forms). The trick is that
I'd like the form packages and forms loaded to be dynamic. Therefore
the main application should be able to "discover" all the form
packages, then allow those discovered forms to be "shown" as
MdiChildren. New forms should be able to be added and discovered
without ever having to recompile the main application. I know I need
to use dynamically loaded assemblies, but I'm not sure how and where
to start.

How would I go about doing this?

Hi Jon,

I don't have neither VS or a manual at hand right now, so i will not
give you a ready example now.
But check "Assembly" class, it should have a method
"LoadAssembly(< DllFileName>)", which will return
an "Assembly" object associated with the dll. Then using Reflection, you
can "extract" classes from the loaded asembly.

I will try to post something as i get to the office

Andrey


Ok, i found a piece of code i used for the task similar to yours - to dynamically load classes from assemblies:
// =============== ======= CODE START =============== =============== ==============

// You shoul add this "using "
using System.Reflecti on;
// Here you load an assembly
private void btnOpenAssembly _Click(object sender, System.EventArg s e)
{
dlgOpen.Filter = "NET Assembly *.dll, *.exe | *.dll; *.exe";
if (dlgOpen.ShowDi alog() != DialogResult.OK ) return;
string fileName = dlgOpen.FileNam e;
// Read
Assembly asm = Assembly.LoadFr om(fileName);
Type[] asm_types = asm.GetTypes();
/*foreach(Type t in mytypes)
{
MethodInfo[] mi = t.GetMethods(fl ags);
Object obj = Activator.Creat eInstance(t);

foreach(MethodI nfo m in mi)
{
m.Invoke(obj, null);
}
}*/
listClasses.Ite ms.Clear();
textMethods.Tex t = "";
foreach(Type t in asm_types)
{
ListViewItem li = new ListViewItem(t. FullName);
li.Tag = t;
listClasses.Ite ms.Add(li);
}
}
//Here you explore it's methods
private void listMethods_Dou bleClick(object sender, System.EventArg s e)
{
if (listClasses.Se lectedItems.Cou nt == 0) return;
ListViewItem li = listClasses.Sel ectedItems[0];
Type t = (Type)li.Tag;
//BindingFlags flags = (BindingFlags.N onPublic | BindingFlags.Pu blic |
// BindingFlags.St atic | BindingFlags.In stance | BindingFlags.De claredOnly);
MethodInfo[] mi = t.GetMethods();
textMethods.Tex t = "";
foreach (MethodInfo m in mi)
{
textMethods.Tex t += ' '+m.Name;
}
}

// =============== ======= CODE END =============== =============== ==============
Code is very amature, but gives you a good start
Hope it helps,
Andrey

Nov 16 '05 #4
JonS. wrote:
Thanks Muzzy,

I'm going to try it out and see what I come up with right now. Since the
object is essentially a form I guess I can use the MdiParent and Show methods
to get it to work dynamically.

What about the whole idea of being able to change/add DLLs (form packages)
while the actual software is running? Is this possible? From what I've read
they say it's doable using different App Domains. Do you know anything about
this?
I've never used App Domains yet, but i use the methods i've shown you for run-time adding/changing plugins.
Having ability to dynamically load/unload new assemblies you get what you want to achieve here

Let me know if the example worked for you or if you need some more explanations!

Andrey
"MuZZy" wrote:

MuZZy wrote:
JonS. wrote:
Hi,

I'm trying to create a Windows Forms portal application and need some
help. What I currently have is a main application (.exe) containing
an MDI form. The idea is that this main application loads forms from
packages (i.e. DLLs containing one or more forms). The trick is that
I'd like the form packages and forms loaded to be dynamic. Therefore
the main application should be able to "discover" all the form
packages, then allow those discovered forms to be "shown" as
MdiChildren . New forms should be able to be added and discovered
without ever having to recompile the main application. I know I need
to use dynamically loaded assemblies, but I'm not sure how and where
to start.

How would I go about doing this?
Hi Jon,

I don't have neither VS or a manual at hand right now, so i will not
give you a ready example now.
But check "Assembly" class, it should have a method
"LoadAssembl y(<DllFileName> )", which will return
an "Assembly" object associated with the dll. Then using Reflection, you
can "extract" classes from the loaded asembly.

I will try to post something as i get to the office

Andrey


Ok, i found a piece of code i used for the task similar to yours - to dynamically load classes from assemblies:
// =============== ======= CODE START =============== =============== ==============

// You shoul add this "using "
using System.Reflecti on;
// Here you load an assembly
private void btnOpenAssembly _Click(object sender, System.EventArg s e)
{
dlgOpen.Filter = "NET Assembly *.dll, *.exe | *.dll; *.exe";
if (dlgOpen.ShowDi alog() != DialogResult.OK ) return;
string fileName = dlgOpen.FileNam e;
// Read
Assembly asm = Assembly.LoadFr om(fileName);
Type[] asm_types = asm.GetTypes();
/*foreach(Type t in mytypes)
{
MethodInfo[] mi = t.GetMethods(fl ags);
Object obj = Activator.Creat eInstance(t);

foreach(MethodI nfo m in mi)
{
m.Invoke(obj, null);
}
}*/
listClasses.Ite ms.Clear();
textMethods.Tex t = "";
foreach(Type t in asm_types)
{
ListViewItem li = new ListViewItem(t. FullName);
li.Tag = t;
listClasses.Ite ms.Add(li);
}
}
//Here you explore it's methods
private void listMethods_Dou bleClick(object sender, System.EventArg s e)
{
if (listClasses.Se lectedItems.Cou nt == 0) return;
ListViewItem li = listClasses.Sel ectedItems[0];
Type t = (Type)li.Tag;
//BindingFlags flags = (BindingFlags.N onPublic | BindingFlags.Pu blic |
// BindingFlags.St atic | BindingFlags.In stance | BindingFlags.De claredOnly);
MethodInfo[] mi = t.GetMethods();
textMethods.Tex t = "";
foreach (MethodInfo m in mi)
{
textMethods.Tex t += ' '+m.Name;
}
}

// =============== ======= CODE END =============== =============== ==============
Code is very amature, but gives you a good start
Hope it helps,
Andrey

Nov 16 '05 #5
JonS. wrote:
Thanks Muzzy,

I'm going to try it out and see what I come up with right now. Since the
object is essentially a form I guess I can use the MdiParent and Show methods
to get it to work dynamically.

What about the whole idea of being able to change/add DLLs (form packages)
while the actual software is running? Is this possible? From what I've read
they say it's doable using different App Domains. Do you know anything about
this?
I've never used App Domains yet, but i use the methods i've shown you for run-time adding/changing plugins.
Having ability to dynamically load/unload new assemblies you get what you want to achieve here

Let me know if the example worked for you or if you need some more explanations!

Andrey
"MuZZy" wrote:

MuZZy wrote:
JonS. wrote:
Hi,

I'm trying to create a Windows Forms portal application and need some
help. What I currently have is a main application (.exe) containing
an MDI form. The idea is that this main application loads forms from
packages (i.e. DLLs containing one or more forms). The trick is that
I'd like the form packages and forms loaded to be dynamic. Therefore
the main application should be able to "discover" all the form
packages, then allow those discovered forms to be "shown" as
MdiChildren . New forms should be able to be added and discovered
without ever having to recompile the main application. I know I need
to use dynamically loaded assemblies, but I'm not sure how and where
to start.

How would I go about doing this?
Hi Jon,

I don't have neither VS or a manual at hand right now, so i will not
give you a ready example now.
But check "Assembly" class, it should have a method
"LoadAssembl y(<DllFileName> )", which will return
an "Assembly" object associated with the dll. Then using Reflection, you
can "extract" classes from the loaded asembly.

I will try to post something as i get to the office

Andrey


Ok, i found a piece of code i used for the task similar to yours - to dynamically load classes from assemblies:
// =============== ======= CODE START =============== =============== ==============

// You shoul add this "using "
using System.Reflecti on;
// Here you load an assembly
private void btnOpenAssembly _Click(object sender, System.EventArg s e)
{
dlgOpen.Filter = "NET Assembly *.dll, *.exe | *.dll; *.exe";
if (dlgOpen.ShowDi alog() != DialogResult.OK ) return;
string fileName = dlgOpen.FileNam e;
// Read
Assembly asm = Assembly.LoadFr om(fileName);
Type[] asm_types = asm.GetTypes();
/*foreach(Type t in mytypes)
{
MethodInfo[] mi = t.GetMethods(fl ags);
Object obj = Activator.Creat eInstance(t);

foreach(MethodI nfo m in mi)
{
m.Invoke(obj, null);
}
}*/
listClasses.Ite ms.Clear();
textMethods.Tex t = "";
foreach(Type t in asm_types)
{
ListViewItem li = new ListViewItem(t. FullName);
li.Tag = t;
listClasses.Ite ms.Add(li);
}
}
//Here you explore it's methods
private void listMethods_Dou bleClick(object sender, System.EventArg s e)
{
if (listClasses.Se lectedItems.Cou nt == 0) return;
ListViewItem li = listClasses.Sel ectedItems[0];
Type t = (Type)li.Tag;
//BindingFlags flags = (BindingFlags.N onPublic | BindingFlags.Pu blic |
// BindingFlags.St atic | BindingFlags.In stance | BindingFlags.De claredOnly);
MethodInfo[] mi = t.GetMethods();
textMethods.Tex t = "";
foreach (MethodInfo m in mi)
{
textMethods.Tex t += ' '+m.Name;
}
}

// =============== ======= CODE END =============== =============== ==============
Code is very amature, but gives you a good start
Hope it helps,
Andrey

Nov 16 '05 #6
Hey Muzzy,

Definitely worked displaying those forms, but I still need to figure the app
domain stuff out. Being able to add and remove packages of forms dynamically
is a must, and from what I've read I can't unload an assemblly, only app
domains, so I need to load these specific assemblies in a seperate app domain
and pass them over to my main app domain.

I'm going to keep looking for information, and hopefully come up with
something.

Sincerely,

Jon

"MuZZy" wrote:
JonS. wrote:
Thanks Muzzy,

I'm going to try it out and see what I come up with right now. Since the
object is essentially a form I guess I can use the MdiParent and Show methods
to get it to work dynamically.

What about the whole idea of being able to change/add DLLs (form packages)
while the actual software is running? Is this possible? From what I've read
they say it's doable using different App Domains. Do you know anything about
this?


I've never used App Domains yet, but i use the methods i've shown you for run-time adding/changing plugins.
Having ability to dynamically load/unload new assemblies you get what you want to achieve here

Let me know if the example worked for you or if you need some more explanations!

Andrey
"MuZZy" wrote:

MuZZy wrote:

JonS. wrote:
>Hi,
>
>I'm trying to create a Windows Forms portal application and need some
>help. What I currently have is a main application (.exe) containing
>an MDI form. The idea is that this main application loads forms from
>packages (i.e. DLLs containing one or more forms). The trick is that
>I'd like the form packages and forms loaded to be dynamic. Therefore
>the main application should be able to "discover" all the form
>packages, then allow those discovered forms to be "shown" as
>MdiChildren . New forms should be able to be added and discovered
>without ever having to recompile the main application. I know I need
>to use dynamically loaded assemblies, but I'm not sure how and where
>to start.
>
>How would I go about doing this?
Hi Jon,

I don't have neither VS or a manual at hand right now, so i will not
give you a ready example now.
But check "Assembly" class, it should have a method
"LoadAssembl y(<DllFileName> )", which will return
an "Assembly" object associated with the dll. Then using Reflection, you
can "extract" classes from the loaded asembly.

I will try to post something as i get to the office

Andrey

Ok, i found a piece of code i used for the task similar to yours - to dynamically load classes from assemblies:
// =============== ======= CODE START =============== =============== ==============

// You shoul add this "using "
using System.Reflecti on;
// Here you load an assembly
private void btnOpenAssembly _Click(object sender, System.EventArg s e)
{
dlgOpen.Filter = "NET Assembly *.dll, *.exe | *.dll; *.exe";
if (dlgOpen.ShowDi alog() != DialogResult.OK ) return;
string fileName = dlgOpen.FileNam e;
// Read
Assembly asm = Assembly.LoadFr om(fileName);
Type[] asm_types = asm.GetTypes();
/*foreach(Type t in mytypes)
{
MethodInfo[] mi = t.GetMethods(fl ags);
Object obj = Activator.Creat eInstance(t);

foreach(MethodI nfo m in mi)
{
m.Invoke(obj, null);
}
}*/
listClasses.Ite ms.Clear();
textMethods.Tex t = "";
foreach(Type t in asm_types)
{
ListViewItem li = new ListViewItem(t. FullName);
li.Tag = t;
listClasses.Ite ms.Add(li);
}
}
//Here you explore it's methods
private void listMethods_Dou bleClick(object sender, System.EventArg s e)
{
if (listClasses.Se lectedItems.Cou nt == 0) return;
ListViewItem li = listClasses.Sel ectedItems[0];
Type t = (Type)li.Tag;
//BindingFlags flags = (BindingFlags.N onPublic | BindingFlags.Pu blic |
// BindingFlags.St atic | BindingFlags.In stance | BindingFlags.De claredOnly);
MethodInfo[] mi = t.GetMethods();
textMethods.Tex t = "";
foreach (MethodInfo m in mi)
{
textMethods.Tex t += ' '+m.Name;
}
}

// =============== ======= CODE END =============== =============== ==============
Code is very amature, but gives you a good start
Hope it helps,
Andrey

Nov 16 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1450
by: web1110 | last post by:
Hi y'all, I was playing with the ability to dynamically create an assembly. I created a windows application in which I created a CSharp program in a disk file, compiled it etc. My problem is that the dll calls MessageBox.Show() and this is causing errors in the compilation. What I need to know is what assemblies must I employ (via 'using' and CompilerParameters.ReferencedAssemblies.Add()) to permit a dynamically
9
4493
by: Ender | last post by:
I have an application that I would like third party developers to be able to create Plug-ins that will be dynamically loaded into our application to extend functionality. I have utilized the "Let Users Add Functionality to Your .NET Applications with Macros and Plug-Ins" article at MSDN for the dynamic loading of DLLs http://msdn.microsoft.com/msdnmag/issues/03/10/Plug-Ins/default.aspx
8
2541
by: Eyeawanda Pondicherry | last post by:
I have put some code together that creates an enum dynamically from some database values. The enum can be read perfectly by an application that references the dynamically generated dll. If I /emit/ a new version of the assembly, and start the application again, the new values will appear for the enum. However, suppose I want the application to remain in a running state.
4
2488
by: BrianS | last post by:
What is the best strategy for dynamic loading private assemblies in asp.net? I understand, and have confirmed, that any dll placed in the app's /bin dir will get loaded on startup. This is not desirable. I have a web service that, based on an input parameter, dynamically loads A, B or C library. I also understand that an separate AppDomain is needed to explicitly unload the Assembly. No other apps will use these assemblies. Do I need...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10212
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7410
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5304
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3962
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.