[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pnet-developers] MethodInfo.Invoke throws unjustified exception
From: |
Bruno Haible |
Subject: |
[Pnet-developers] MethodInfo.Invoke throws unjustified exception |
Date: |
Sat, 27 Dec 2003 14:54:30 +0100 |
User-agent: |
KMail/1.5 |
Using pnet-0.6.0.
Invoke with a non-static method and a null object must throw a TargetException.
However, Invoke with a static method and a non-null object is fine - the
implementation should not throw an error here.
========================== hello.cs ==============================
using System;
using System.Reflection;
class Hello {
public static int FooBar () { return 42; }
public Hello () {}
static void Main () {
Hello h = new Hello();
try {
MethodInfo m = h.GetType().GetMethod("FooBar", new Type[0]);
m.Invoke(h, new Object[0]);
} catch (Exception e) {
Console.Error.WriteLine(e);
}
}
}
===================================================================
$ cscc hello.cs -o hello.exe
$ ilrun hello.exe
System.Reflection.TargetException: Instance method cannot be invoked on a null
target
at System.Reflection.ClrMethod.Invoke(Object, BindingFlags, Binder,
Object[], CultureInfo)
at System.Reflection.MethodBase.Invoke(Object, Object[]) in
./System/Reflection/MethodBase.cs
at Hello.Main()
- [Pnet-developers] MethodInfo.Invoke throws unjustified exception,
Bruno Haible <=