E
Ender
I have an application that I would like third party developers to be
able to create Plug-ins that will be dynamically loaded into our
application to extend functionality.
I have utilized the "Let Users Add Functionality to Your .NET
Applications with Macros and Plug-Ins" article at MSDN for the dynamic
loading of DLLs
http://msdn.microsoft.com/msdnmag/issues/03/10/Plug-Ins/default.aspx
We have an interface defined and everything was working fine. Users
would implement the interface and we would load the object dynamically
and our client application would properly implement the functionality.
I then went and create a Library class that would contain objects that
the third party developers need for utilization with their application
development. We have a reference to this Library class in our
Interface, and users need to implement properties that our part of the
library class. Upon adding this, and implementing the interface, our
dynamic loading of DLLs no longer functioned. I get a
ReflectionTypeLoadException error
"One or more of the types in the assembly unable to load."
System.SystemException: {"One or more of the types in the assembly
unable to load."}
_classes: {Length=2}
_exceptions: {Length=1}
LoaderExceptions: {Length=1}
Types: {Length=2}
and if I look at the LoaderExceptions the message I get is
{"Com.Corp.CorpImage.CorpImage"}
System.SystemException: {"Method get_CorpImageFields in type
Com.Corp.CorpImage.CorpImage from assembly CorpImage,
Version=1.0.1741.17159, Culture=neutral, PublicKeyToken=null does not
have an implementation."}
AssemblyName: "CorpImage, Version=1.0.1741.17159, Culture=neutral,
PublicKeyToken=null"
ClassName: "CorpImage"
Message: "Method get_CorpImageFields in type
Com.Corp.CorpImage.CorpImage from assembly CorpImage,
Version=1.0.1741.17159, Culture=neutral, PublicKeyToken=null does not
have an implementation."
MessageArg: "get_CorpImageFields"
ResourceId: 6012
TypeName: "Com.Corp.CorpImage.CorpImage"
I can get by the loading issue by skipping the loading of the Library
class when querying the types. While it's a work around, I am not
sure if it will enable everything to work down the road. I am also
unsure what I did
Why does skipping trying to iterate the getTypes
of the Library dll enable things to work?
Again, the code is pretty similar to the one mentioned in the above
MSDN article. The change to the code I made to skip loading is as
follows...
private String[] DiscoverPluginAssembliesHelper(
String path, PluginCriteria criteria, Type criteriaType)
{
String[] assemblies;
// Get .dll names
path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, path);
assemblies = Directory.GetFiles(path, "*.dll");
try
{
if(assemblies.Length != 0)
{
ArrayList assembliesIncluded = new ArrayList();
foreach(String s in assemblies)
{
// Load the assembly (it it's not the control library)
if (s.ToLower().IndexOf("controllibrary") < 0)
{
Assembly assembly = Assembly.LoadFrom(s);
// Find matching type?
Type[] types = assembly.GetTypes();
foreach(Type t in types)
{
if(IncludeType(t, criteria, criteriaType))
{
assembliesIncluded.Add(s);
break; // match found, move on
}
}
}
}
// Get array of matching assemblies
assemblies = (String[])assembliesIncluded.ToArray(
typeof(String));
}
}
catch (ReflectionTypeLoadException oEx)
{
throw new Exception("Error discovering plugin assemblies",oEx);
}
catch (Exception oEx)
{
throw new Exception("Error discovering plugin assemblies",oEx);
}
return assemblies;
}
Any insights greatly appreciated
Endymion Keats
able to create Plug-ins that will be dynamically loaded into our
application to extend functionality.
I have utilized the "Let Users Add Functionality to Your .NET
Applications with Macros and Plug-Ins" article at MSDN for the dynamic
loading of DLLs
http://msdn.microsoft.com/msdnmag/issues/03/10/Plug-Ins/default.aspx
We have an interface defined and everything was working fine. Users
would implement the interface and we would load the object dynamically
and our client application would properly implement the functionality.
I then went and create a Library class that would contain objects that
the third party developers need for utilization with their application
development. We have a reference to this Library class in our
Interface, and users need to implement properties that our part of the
library class. Upon adding this, and implementing the interface, our
dynamic loading of DLLs no longer functioned. I get a
ReflectionTypeLoadException error
"One or more of the types in the assembly unable to load."
System.SystemException: {"One or more of the types in the assembly
unable to load."}
_classes: {Length=2}
_exceptions: {Length=1}
LoaderExceptions: {Length=1}
Types: {Length=2}
and if I look at the LoaderExceptions the message I get is
{"Com.Corp.CorpImage.CorpImage"}
System.SystemException: {"Method get_CorpImageFields in type
Com.Corp.CorpImage.CorpImage from assembly CorpImage,
Version=1.0.1741.17159, Culture=neutral, PublicKeyToken=null does not
have an implementation."}
AssemblyName: "CorpImage, Version=1.0.1741.17159, Culture=neutral,
PublicKeyToken=null"
ClassName: "CorpImage"
Message: "Method get_CorpImageFields in type
Com.Corp.CorpImage.CorpImage from assembly CorpImage,
Version=1.0.1741.17159, Culture=neutral, PublicKeyToken=null does not
have an implementation."
MessageArg: "get_CorpImageFields"
ResourceId: 6012
TypeName: "Com.Corp.CorpImage.CorpImage"
I can get by the loading issue by skipping the loading of the Library
class when querying the types. While it's a work around, I am not
sure if it will enable everything to work down the road. I am also
unsure what I did

of the Library dll enable things to work?
Again, the code is pretty similar to the one mentioned in the above
MSDN article. The change to the code I made to skip loading is as
follows...
private String[] DiscoverPluginAssembliesHelper(
String path, PluginCriteria criteria, Type criteriaType)
{
String[] assemblies;
// Get .dll names
path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, path);
assemblies = Directory.GetFiles(path, "*.dll");
try
{
if(assemblies.Length != 0)
{
ArrayList assembliesIncluded = new ArrayList();
foreach(String s in assemblies)
{
// Load the assembly (it it's not the control library)
if (s.ToLower().IndexOf("controllibrary") < 0)
{
Assembly assembly = Assembly.LoadFrom(s);
// Find matching type?
Type[] types = assembly.GetTypes();
foreach(Type t in types)
{
if(IncludeType(t, criteria, criteriaType))
{
assembliesIncluded.Add(s);
break; // match found, move on
}
}
}
}
// Get array of matching assemblies
assemblies = (String[])assembliesIncluded.ToArray(
typeof(String));
}
}
catch (ReflectionTypeLoadException oEx)
{
throw new Exception("Error discovering plugin assemblies",oEx);
}
catch (Exception oEx)
{
throw new Exception("Error discovering plugin assemblies",oEx);
}
return assemblies;
}
Any insights greatly appreciated
Endymion Keats