[enum]::Getnames($xlConstants) fails

I have this one line of code:

the purpose being to enumerate all symbolic names (in EXCEL).

I am getting the error message:

 Exception calling GetNames with “1” arguments. “Value cannot be null.  Parameter name: enumType”

Why? Would be grateful for any tips and advice.

#Requires -Version 5

enum xlConstants {


You’re trying to pass an empty variable to the GetNames method of the enum class. That method accepts an enum type as in the example above.
Enum values can have no spaces, special characters, or numbers.

This is not a PowerShell see, you just happen to be doing that here.
This is a raw .Net namespace call and you are bound to what it expects and PowerShell can only abide by that.

Enum.GetNames(Type) Method Namespace: System Assemblies: System.Runtime.dll, mscorlib.dll, netstandard.dll https://docs.microsoft.com/en-us/dotnet/api/system.enum.getnames?redirectedfrom=MSDN&view=netframework-4.8#System_Enum_GetNames_System_Type_
# C#
        Console.WriteLine("The members of the Styles enum are:");
        foreach(string s in Enum.GetNames(typeof(Styles)))

So, like this articles shows, you need to be passing an array.
Working With Enums In PowerShell

How are you populating …


See also this:
#PSTip Working with Excel constants

# create Excel object
$xl = New-Object -ComObject Excel.Application
# create new PowerShell object
$xlEnum = New-Object -TypeName PSObject
# get all Excel exported types of type Enum
$xl.GetType().Assembly.GetExportedTypes() | Where-Object {$_.IsEnum} | ForEach-Object {
    # create properties from enum values
    $enum = $_
    $enum.GetEnumNames() | ForEach-Object {
        $xlEnum | Add-Member -MemberType NoteProperty -Name $_ -Value $enum::($_)

And this…
Using enums in Powershell

Better, if you could post the whole function/script you have to avoid guessing.