I have two class libraries core
and plugins
and a WPF application that uses these two libraries. In core
I dynamically load the plugins
as follows:
try
{
Assembly assembly = Assembly.LoadFile("plugins.dll");
}
After I load the plugins.dll
I get the types in the plugins
that has implemented Node
abstract class from core
library, that is a class defined in the core
. This is the scenario that I used to develop and extensible application. Somewhere in my core
library I need to traverse all fields of Node
classes loaded from plugins
. It works nice for all fields like int
, double
and other custom classes that are defined inside plugins
library.
theList = assembly.GetTypes().ToList().Where(t => t.BaseType == typeof(Node)).ToList();
var fieldInfos = theList[0].GetType().GetRuntimeFields();
foreach (var item in fieldInfos)
{
Type type = item.FieldType;
// Here I get exception for fields like XYZ that defined in
// Revit API though for fields like Int and double it works charm
}
But the problem is that in plugins
project, I also use Revit API, and when the above loop reaches to a field that comes from RevitAPI.dll
I get the following exception (I tried target platform Any and x86):
An unhandled exception of type 'System.BadImageFormatException' occurred in mscorlib.dll
Additional information: Could not load file or assembly 'RevitAPI,
Version=2015.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its
dependencies. An attempt was made to load a program with an incorrect format.
When I change the target platform in build section of all 3 projects to x64 I get this exception, instead:
An unhandled exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
Additional information: Could not load file or assembly 'RevitAPI.dll'
or one of its dependencies. The specified module could not be found.
Aucun commentaire:
Enregistrer un commentaire