Home Bug Reports

C#: loadPlugin() in PluginManagerI.cs

kwaclawkwaclaw Oshawa, CanadaMember Karl WaclawekOrganization: Personal
I am trying to write an SSL plugin for IceCS under .NET 2.0.
However, I cannot get it to load. As far as I understand
assembly loading, the code in PluginManagerI.loadPlugin()
will not work.

This line:
System.Type c = System.Type.GetType(className);
works only if the plugin assembly is already loaded, which
seems like a catch 22, since loading the assembly is
the purpose of loadPlugin().

This line:
System.Type c = IceInternal.AssemblyUtil.findType(className);
won't work either, as the new plugin is not referenced by IceCS.dll.

I suggest that for loading a plugin under .NET, one specifies
two identifiers, an assembly name/path, and a class name
(e.g. IceSsl.PluginFactory).

The code belwo seems to work for me. It assumes that the
value of the Ice.Plugin.IceSSL property is the class name,
followed by @ and then the assembly file path. Here it is,

private void loadPlugin(string name, string className, string[] args)
{
Debug.Assert(_communicator != null);

// separate out assembly path
int sepPos = className.IndexOf('@');
if (sepPos == -1) {
PluginInitializationException e = new PluginInitializationException();
e.reason = "no assembly path provided: " + className;
throw e;
}

Assembly pluginAssembly = null;
string assemblyName = className.Substring(sepPos + 1);
try {
if (File.Exists(assemblyName))
pluginAssembly = Assembly.LoadFrom(assemblyName);
else
pluginAssembly = Assembly.Load(assemblyName);
}
catch {
PluginInitializationException e = new PluginInitializationException();
e.reason = "cannot load assembly: " + assemblyName;
throw e;
}

//
// Instantiate the class.
//
PluginFactory factory = null;
className = className.Substring(0, sepPos);
System.Type c = pluginAssembly.GetType(className);

.... and so forth, as in the original code.

Comments

Sign In or Register to comment.