Click here to Skip to main content
6,631,889 members and growing! (17,225 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), ASP.NET, ADO.NET, Dev
Posted:1 Apr 2008
Views:7,562
Bookmarked:16 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
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

4
1 vote, 12.5%
5

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


Member

Occupation: Software Developer
Location: Germany Germany

Other popular C# articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 1 of 1 (Total in Forum: 1) (Refresh)FirstPrevNext
GeneralIn the next Article... PinsupporterMark 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-2009
Web22 | Advertise on the Code Project