5,699,997 members and growing! (17,010 online)
Email Password   helpLost your password?
Languages » C# » Applications     Beginner License: The Code Project Open License (CPOL)

How can you load .NET assemblies dynamicly

By Steingrebe

not really a new but a Solution
C#, .NET (.NET 2.0, .NET), ADO.NET, ASP.NET, Dev

Posted: 1 Apr 2008
Updated: 1 Apr 2008
Views: 3,993
Bookmarked: 9 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
8 votes for this Article.
Popularity: 1.67 Rating: 1.85 out of 5
5 votes, 62.5%
1
1 vote, 12.5%
2
1 vote, 12.5%
3
0 votes, 0.0%
4
1 vote, 12.5%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Introduction

This is my first English article, so excuse my horrible English.

The first Time i start to develop a .NET Application i had to load a DLL dynamicly. Puh... I don't

know how but i wrote a Function to do that.

Next Time i need a Function to load a DLL from a Interface. Ok Copy the first Function and change the Parameters.

After that i must load not only one DLL so we can have many. Ok Copy the first Function and change the Parameters.

Hmm, wait a moment. There is many Space to do it in the generic way.

Background

The Generic way means that you have, at designtime, no Idea what objects at runtime you will work with.

public static class ModuleLoader<T>

Using the code

Functionlist:

Load only one Module

public static T LoadModule(Guid moduleId)
public static T LoadModule(Guid moduleId, string path)
public static T LoadModule(Guid moduleId, string path, string fileExtension)

Load a list of Modules

public static List<T> LoadModuleList()
public static List<T> LoadModuleList(string path)
public static List<T> LoadModuleList(Guid moduleId, string path, string fileExtension)

When you want to load a list of Modules, i think you will use a Interface as T

Example:

Loads all Assemblies that implement the IPlugIn Interface in the current Directory

List<IPlugIn> pluginList = ModuleLoader<IPlugIn>.LoadModuleList();

Loads a given Assembly that implement the IPlugIn Interface in the current Directory. Where pluginId the TypeGuid of the given PlugIn is.

IPlugIn plugin = ModuleLoader<IPlugIn>.LoadModule(pluginId);

In the next Article i will explain how you can use the ModuleLoader with a AppDomain to load and unload at runtime.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Steingrebe



Occupation: Software Developer
Location: Germany Germany

Other popular C# articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 1 of 1 (Total in Forum: 1) (Refresh)FirstPrevNext
GeneralIn the next Article...supporterMark Nischalke8:43 1 Apr '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 1 Apr 2008
Editor:
Copyright 2008 by Steingrebe
Everything else Copyright © CodeProject, 1999-2008
Web07 | Advertise on the Code Project