2

I'm reading information on various objects from an XML file and need to instantiate and set values on these objects from PowerShell.

This is a sample where UInt32.Parse(string) should be retrieved using Reflection. The problem is the $mi variable is null:

$o = new-object -typename "System.UInt32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
$mi = $o.GetType().GetMethod("Parse", [type[]] @([string].GetType()) )

The corresponding C# code works:

UInt32 o = 0;
var mi = o.GetType().GetMethod("Parse", new [] {typeof(string)});

Any ideas?

1 Answer 1

1

Do you need to use reflection? Perhaps you could use $parse = [system.uint32]::Parse and $parse.Invoke($arg) instead.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.