It turned out to be just a stupid mistake on my side (*blush*), I had forgotten to 
initialize a parameter array with the input value. Now it works like a charm.

Btw, I got some rather confusing error information back from InvokeMember when passing 
it a null parameter array: When setting a property, I got back a message telling me 
"property not found". When setting a field, I got a message telling me that I needed 
to specify the SetField binding flag.

Thanks for any help,
Kjell

> -----Original Message-----
> From: MikeF [mailto:[EMAIL PROTECTED]
> Sent: 13. oktober 2003 20:53
> To: [EMAIL PROTECTED]
> Subject: Re: [ADVANCED-DOTNET] Error when setting a static
> field using Type.InvokeMember
>
>
> I wasn't able to duplciate the problem you stated.  The
> following code works for me just fine.
>
> public class Class1()
> { public static int testValue = 0; }
>
> Class1 cla = new Class1();
>
> Type t = typeof(Class1);
>
> // Try against instance of class
> t.InvokeMember("testValue",
>  BindingFlags.DeclaredOnly |
>  BindingFlags.Public | BindingFlags.NonPublic |
> BindingFlags.Static | BindingFlags.SetField, null, cla, new
> Object [] {5});
>
> // Try against no direct instance of class
> t.InvokeMember("testValue",  BindingFlags.DeclaredOnly |
> BindingFlags.Public | BindingFlags.NonPublic |
> BindingFlags.Static | BindingFlags.SetField, null, null, new
> Object [] {6});
>
> ===================================
> This list is hosted by DevelopMentor(r)  http://www.develop.com
> NEW! ASP.NET courses you may be interested in:
>
> 2 Days of ASP.NET, 29 Sept 2003, in Redmond
> http://www.develop.com/courses/2daspdotnet
>
> Guerrilla
> ASP.NET, 13 Oct 2003, in Boston
> http://www.develop.com/courses/gaspdotnet
>
> View archives and
> manage your subscription(s) at http://discuss.develop.com
>

===================================
This list is hosted by DevelopMentor�  http://www.develop.com
NEW! ASP.NET courses you may be interested in:

2 Days of ASP.NET, 29 Sept 2003, in Redmond
http://www.develop.com/courses/2daspdotnet

Guerrilla ASP.NET, 13 Oct 2003, in Boston
http://www.develop.com/courses/gaspdotnet

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to