473,404 Members | 2,137 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,404 software developers and data experts.

Using assemblies in runtime?

Hello..

Just wondering, is it possible to make a folder with assemblies and have the
application to read it in runtime?

Possible use: Could be menues, if the menu assembly exists in the folder
then it's added to the gui !
Reason: licensing
Kind regards
Nov 16 '05 #1
2 1392
Janus... No problem, but there are security risks.

http://www.geocities.com/jeff_louie/OOP/oop13.htm

// now dynamically load class DrawPlugIn.Triangle which
// implements interface MyInterface.IDrawable
Assembly assembly= null;
try
{
// tell app where to look for plugins
AppDomain.CurrentDomain.AppendPrivatePath("plugins ");
// get absolute path to our private assemblies
string path=
AppDomain.CurrentDomain.BaseDirectory+"plugins";

// create plugins folder if one does not exist
DirectoryInfo info= new DirectoryInfo(path);
if (!info.Exists){ info.Create();}
// discover all dlls in plugins folder
string[] dir= Directory.GetFiles(path,"*.dll");
// iterate over files in folder plugins
foreach (string s in dir)
{
string dll= Path.GetFileNameWithoutExtension(s);
assembly= Assembly.Load(dll); // in folder
plugins
Type[] types= assembly.GetTypes();
foreach(Type t in types)
{
Console.WriteLine("Type: {0}",t);
try
{
// only load if implements
IDrawable
// use fully qualified name!
if
(t.GetInterface("MyInterface.IDrawable")!= null)
//if
(typeof(IDrawable).IsAssignableFrom(t)) // safer
{
// dynamically load this
class
object obj=
Activator.CreateInstance(t);
drawableList.Add(obj);
// no need to cast
}
}
catch(Exception e)
{
Console.WriteLine(e);
}
}
}
}
catch(Exception e)
{
Console.WriteLine(e);
}

Regards,
Jeff
Just wondering, is it possible to make a folder with assemblies and

have the
application to read it in runtime?<
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #2
It is possible,you can use the static method Load of the Assembly to load the assembly to the AppDomain and use reflection to access the metadata at runtime.
Nov 16 '05 #3

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

Similar topics

12
by: Mark Broadbent | last post by:
Hi guys, just going through remoting at the moment and a couple of questions relating to .net in general has surfaced. Firstly I have seen in the designer that for the namespace and many of its...
0
by: Paul | last post by:
Snippet from web.config: <startup> <supportedRuntime version="v1.0.3705" /> <requiredRuntime version="v1.0.3705" safemode="true"/> </startup> <runtime> <assemblyBinding...
8
by: Subra Mallampalli | last post by:
Hi, I am trying to use <runtime> section within the web.config file. However, the contents of the <runtime> section seem to be ignored. What am i missing here? Is <runtime> section not used by...
2
by: Luis Arvayo | last post by:
Actually it is: How to define the plugin assemblies path in order to find other assemblies which the plugin depends on. Example: If I have: c:\myapp\application.exe
4
by: Tony Johansson | last post by:
Hello! I have read some info on the WWW about GAC It says the following. "If you want to use an assembly from the GAC, you should drop your assemblies into a local folder, and then add a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.