views:

88

answers:

3

I've done plugin architectures in Win32 & C/C++ for years, with extension points dynamically loaded from DLLs with LoadLibrary, GetProcAddress, etc.

Now the time has come to C#. What are the corresponding steps there - dynamically load an assembly? Or is it a completely different schema?

+3  A: 

Generally, you can look around where you expect plugins, load the assemblies and look for certain classes. Usually plugins advertise themselves by extending some sort of plugin base class or implementing an interface.

Another option would be MEF which will also be part of .NET 4 but the preview releases work on the current .NET framework, too.

Joey
MEF has been around for a while, and runs on 3.5, if not 3.0.
Jay
@Jay: Did I say anything about it *not* running currently? Clarifying, though. However, I'm not entirely sure how good an idea it is to use the preview releases in applications. I've done that once and by now the API did change quite a bit.
Joey
+1  A: 

You can use classes from System.Addin namespace. See this discussion: Choosing between MEF and MAF (System.AddIn)

Here is a demo too: AddIn Enabled Applications

Another solution is to use Mono.AddIn which seems quite powerful.

Giorgi
+1  A: 

In .Net applications we can use AppDomain and AppDomain.CurrentAppDomain to load assemblies dynamically to our application .The problem is that you can unload an assembly once it has been loaded to a AppDomain.There's a workaround to solve this problem that you can load these kind of assemblies in a different AppDomain and unload it whenever you don't want those assemblies.but this approach is very compicated because passing objects between two assemblies in two different AppDomain it's not that easy.

Beatles1692
I think you meant "can *NOT* load" instead of "...can load..."
Kevin Brock
I meant you can unload the other AppDomain
Beatles1692
Passing objects it's not that easy and has to be done with a lot of care, it is very easy to make a little mistake and make the main appdomain silently load your assembly.
jmservera