Archived
This forum has been archived. Please start a new discussion on GitHub.
C#: loadPlugin() in PluginManagerI.cs
kwaclaw
Oshawa, Canada
in Bug Reports
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.
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.
0
Comments
-
Please see this post regarding our support policy:
http://www.zeroc.com/vbulletin/showthread.php?t=16970 -
marc wrote:Please see this post regarding our support policy:
http://www.zeroc.com/vbulletin/showthread.php?t=1697
I don't request support, I am just bringing this to your attention.0 -
Thanks for the bug report, I'll have a look at fixing this for the next release.0