[rdnzl-devel] Problem with invoking static member
Edi Weitz
edi at agharta.de
Wed Feb 8 20:42:02 UTC 2006
Hi!
On Wed, 8 Feb 2006 14:31:10 -0500 (EST), Jim Sokoloff <jim at sokoloff.com> wrote:
> I'm having trouble invoking a static member on a class.
>
> I've reduced the case to the following simple test case, and I
> suspect I may be missing somewhat simple. (I'm far from a Lisp
> wizard. Far...)
>
> Basically, I'm trying to load a C# assembly, and be able to call a
> static method on it. I can call instance methods without issue, but
> make-type-from-name is not working the way I expect it should, and
> therefore, calling static methods fails.
Your problem can be best described with this short C# program:
using System;
using System.Reflection;
public class Test {
public static void Main() {
// insert correct path to LispSample1.dll here
Assembly a = Assembly.LoadFrom("C:\\Documents and Settings\\edi\\Desktop\\LispSample1.dll");
Type t1 = a.GetType("LispSample1.Parrot");
String s = t1.FullName;
Type t2 = Type.GetType(s);
try {
Console.WriteLine("Success: " + t2.Name);
} catch (NullReferenceException) {
Console.WriteLine("Failed");
}
}
}
If I run this, I get "Failed" on the console. This is because
Type.GetType can't create the type from the name although the name is
fully qualified. This happens because you use Assembly.LoadFrom and
this is obviously unrelated to RDNZL.
I can't cite chapter and verse in the .NET documentation but I
immediately recognized the problem because I was bitten by it myself.
If you put your DLL into a folder where the system will find it and
then use it like AproposGui is used in the RDNZL examples, everything
should work fine. At least it works for me, I just tested it with LW.
HTH,
Edi.
More information about the rdnzl-devel
mailing list