473,406 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 1211
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.Reflection;
// Here you load an assembly
private void btnOpenAssembly_Click(object sender, System.EventArgs e)
{
dlgOpen.Filter = "NET Assembly *.dll, *.exe | *.dll; *.exe";
if (dlgOpen.ShowDialog() != DialogResult.OK) return;
string fileName = dlgOpen.FileName;
// Read
Assembly asm = Assembly.LoadFrom(fileName);
Type[] asm_types = asm.GetTypes();
/*foreach(Type t in mytypes)
{
MethodInfo[] mi = t.GetMethods(flags);
Object obj = Activator.CreateInstance(t);

foreach(MethodInfo m in mi)
{
m.Invoke(obj, null);
}
}*/
listClasses.Items.Clear();
textMethods.Text = "";
foreach(Type t in asm_types)
{
ListViewItem li = new ListViewItem(t.FullName);
li.Tag = t;
listClasses.Items.Add(li);
}
}
//Here you explore it's methods
private void listMethods_DoubleClick(object sender, System.EventArgs e)
{
if (listClasses.SelectedItems.Count == 0) return;
ListViewItem li = listClasses.SelectedItems[0];
Type t = (Type)li.Tag;
//BindingFlags flags = (BindingFlags.NonPublic | BindingFlags.Public |
// BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly);
MethodInfo[] mi = t.GetMethods();
textMethods.Text = "";
foreach (MethodInfo m in mi)
{
textMethods.Text += ' '+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.Reflection;
// Here you load an assembly
private void btnOpenAssembly_Click(object sender, System.EventArgs e)
{
dlgOpen.Filter = "NET Assembly *.dll, *.exe | *.dll; *.exe";
if (dlgOpen.ShowDialog() != DialogResult.OK) return;
string fileName = dlgOpen.FileName;
// Read
Assembly asm = Assembly.LoadFrom(fileName);
Type[] asm_types = asm.GetTypes();
/*foreach(Type t in mytypes)
{
MethodInfo[] mi = t.GetMethods(flags);
Object obj = Activator.CreateInstance(t);

foreach(MethodInfo m in mi)
{
m.Invoke(obj, null);
}
}*/
listClasses.Items.Clear();
textMethods.Text = "";
foreach(Type t in asm_types)
{
ListViewItem li = new ListViewItem(t.FullName);
li.Tag = t;
listClasses.Items.Add(li);
}
}
//Here you explore it's methods
private void listMethods_DoubleClick(object sender, System.EventArgs e)
{
if (listClasses.SelectedItems.Count == 0) return;
ListViewItem li = listClasses.SelectedItems[0];
Type t = (Type)li.Tag;
//BindingFlags flags = (BindingFlags.NonPublic | BindingFlags.Public |
// BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly);
MethodInfo[] mi = t.GetMethods();
textMethods.Text = "";
foreach (MethodInfo m in mi)
{
textMethods.Text += ' '+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
"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.Reflection;
// Here you load an assembly
private void btnOpenAssembly_Click(object sender, System.EventArgs e)
{
dlgOpen.Filter = "NET Assembly *.dll, *.exe | *.dll; *.exe";
if (dlgOpen.ShowDialog() != DialogResult.OK) return;
string fileName = dlgOpen.FileName;
// Read
Assembly asm = Assembly.LoadFrom(fileName);
Type[] asm_types = asm.GetTypes();
/*foreach(Type t in mytypes)
{
MethodInfo[] mi = t.GetMethods(flags);
Object obj = Activator.CreateInstance(t);

foreach(MethodInfo m in mi)
{
m.Invoke(obj, null);
}
}*/
listClasses.Items.Clear();
textMethods.Text = "";
foreach(Type t in asm_types)
{
ListViewItem li = new ListViewItem(t.FullName);
li.Tag = t;
listClasses.Items.Add(li);
}
}
//Here you explore it's methods
private void listMethods_DoubleClick(object sender, System.EventArgs e)
{
if (listClasses.SelectedItems.Count == 0) return;
ListViewItem li = listClasses.SelectedItems[0];
Type t = (Type)li.Tag;
//BindingFlags flags = (BindingFlags.NonPublic | BindingFlags.Public |
// BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly);
MethodInfo[] mi = t.GetMethods();
textMethods.Text = "";
foreach (MethodInfo m in mi)
{
textMethods.Text += ' '+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
"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.Reflection;
// Here you load an assembly
private void btnOpenAssembly_Click(object sender, System.EventArgs e)
{
dlgOpen.Filter = "NET Assembly *.dll, *.exe | *.dll; *.exe";
if (dlgOpen.ShowDialog() != DialogResult.OK) return;
string fileName = dlgOpen.FileName;
// Read
Assembly asm = Assembly.LoadFrom(fileName);
Type[] asm_types = asm.GetTypes();
/*foreach(Type t in mytypes)
{
MethodInfo[] mi = t.GetMethods(flags);
Object obj = Activator.CreateInstance(t);

foreach(MethodInfo m in mi)
{
m.Invoke(obj, null);
}
}*/
listClasses.Items.Clear();
textMethods.Text = "";
foreach(Type t in asm_types)
{
ListViewItem li = new ListViewItem(t.FullName);
li.Tag = t;
listClasses.Items.Add(li);
}
}
//Here you explore it's methods
private void listMethods_DoubleClick(object sender, System.EventArgs e)
{
if (listClasses.SelectedItems.Count == 0) return;
ListViewItem li = listClasses.SelectedItems[0];
Type t = (Type)li.Tag;
//BindingFlags flags = (BindingFlags.NonPublic | BindingFlags.Public |
// BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly);
MethodInfo[] mi = t.GetMethods();
textMethods.Text = "";
foreach (MethodInfo m in mi)
{
textMethods.Text += ' '+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
"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.Reflection;
// Here you load an assembly
private void btnOpenAssembly_Click(object sender, System.EventArgs e)
{
dlgOpen.Filter = "NET Assembly *.dll, *.exe | *.dll; *.exe";
if (dlgOpen.ShowDialog() != DialogResult.OK) return;
string fileName = dlgOpen.FileName;
// Read
Assembly asm = Assembly.LoadFrom(fileName);
Type[] asm_types = asm.GetTypes();
/*foreach(Type t in mytypes)
{
MethodInfo[] mi = t.GetMethods(flags);
Object obj = Activator.CreateInstance(t);

foreach(MethodInfo m in mi)
{
m.Invoke(obj, null);
}
}*/
listClasses.Items.Clear();
textMethods.Text = "";
foreach(Type t in asm_types)
{
ListViewItem li = new ListViewItem(t.FullName);
li.Tag = t;
listClasses.Items.Add(li);
}
}
//Here you explore it's methods
private void listMethods_DoubleClick(object sender, System.EventArgs e)
{
if (listClasses.SelectedItems.Count == 0) return;
ListViewItem li = listClasses.SelectedItems[0];
Type t = (Type)li.Tag;
//BindingFlags flags = (BindingFlags.NonPublic | BindingFlags.Public |
// BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly);
MethodInfo[] mi = t.GetMethods();
textMethods.Text = "";
foreach (MethodInfo m in mi)
{
textMethods.Text += ' '+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
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...
9
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...
8
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...
4
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.