Search code examples
powershell

strange behaviour in [array] Calling Address method


I've tested this on Win XP and Windows Server 2008 R2 in Powershell 2.0:

$a = 1,2,3,4 # a simple [object[]] but any other Type is good

if I do:

$a.addres()

the return error is (correctly):

Method invocation failed because [System.Object[]] doesn't contain a method named 'addres'.

But if I do:

$a.address()

the error is:

Cannot find an overload for "Address" and the argument count: "0".

But doing:

$a.address(2)

close powershell console with an 'Problem Event Name: APPCRASH'

starting from that [system.array] has not a method called address how powershell try to call an existing method?


Solution

  • [System.Array] has .Get, .Set and .Address methods that are available via the .Net runtime but are not normally used in PowerShell code. Have a look at this StackOverflow post: