Click here to Skip to main content
Licence CPOL
First Posted 1 Apr 2008
Views 13,861
Downloads 147
Bookmarked 25 times

How Can You Load .NET Assemblies Dynamically

By | 1 Apr 2008 | Article
Not really new, but a solution
 
Part of The SQL Zone sponsored by
See Also

Introduction

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

The first time I started developing a .NET application, I had to load a DLL dynamically. I did not know how to do it, but I wrote a function to do that. The next time I need a function to load a DLL from an Interface, I copy the first function and change the parameters. After that, I load not only one DLL so we can have many. Copy the first function and change the parameters.

Hmm, wait a moment. There is a lot of 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 an 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 is the TypeGuid of the given PlugIn.

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

In the next article, I will explain how you can use the ModuleLoader with an AppDomain to load and unload at runtime.

History

  • 1st April, 2008: Initial post

License

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

About the Author

Steingrebe

Software Developer (Senior)

Germany Germany

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralIn the next Article... PinmemberMark Nischalke7:43 1 Apr '08  
"In the next Article"
 
Why didn't you just expand this, it's barely worth calling an article as is. Not even enough for a blog entry.
 

only two letters away from being an asset

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120529.1 | Last Updated 1 Apr 2008
Article Copyright 2008 by Steingrebe
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid