C# Assembly.GetTypes() - ReflectionTypeLoadException

Posted by Veskechky on Stack Overflow See other posts from Stack Overflow or by Veskechky
Published on 2010-04-17T12:05:16Z Indexed on 2010/04/17 12:13 UTC
Read the original article Hit count: 755

Filed under:
|
|
|

We implement a plugin framework for our application and load plugin assemblies using Assembly.Loadfrom. We then use GetTypes() and further examine the types with each plugin file for supported Interfaces.

A path for the plugins is provided by the user and we cycle through each of the files in the folder to see if it (the plugin) supports our plugin interface. If it does, we create an instance, if not we move onto the next file.

We build two versions of software from the one code base (appA_1 and appA_2).

Loading the plugins works well when the plugins are loaded by the application that was built at the same time as the plugin file. However if we build appA_2 and point to the plugin folder of appA_1, we get an exception when GetTypes() is called.

A basic version of our code is;

var pluginAssembly = Assembly.LoadFrom(FileName);    
foreach (var pluginType in pluginAssembly.GetTypes())
{

We get a "ReflectionTypeLoadException" exception.

This is concerning because we want our application to be able to load the types of any plugin, built by anyone. Is there something we are missing?

© Stack Overflow or respective owner

Related posts about c#

Related posts about assembly