powershellwrapper icon indicating copy to clipboard operation
powershellwrapper copied to clipboard

Error trying to call get-itglueflexibleassetfields

Open ghost opened this issue 4 years ago • 5 comments

Symptom: Get-ITGlueFlexibleAssetFields has no tab-completion for params Running: get-help Get-ITGlueFlexibleAssetFields Results:

get-help : Unable to find type [Nullable[String]]. Details: GenericArguments[0], 'System.String', on
'System.Nullable`1[T]' violates the constraint of type 'T'.
At line:1 char:1
+ get-help Get-ITGlueFlexibleAssetFields
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Nullable[String]:GenericTypeName) [Get-Help], RuntimeException
    + FullyQualifiedErrorId : TypeNotFoundWithMessage,Microsoft.PowerShell.Commands.GetHelpCommand

Environment

Please share additional details about your environment. Version information for:

  • PowerShell

Name Value


PSVersion 5.1.19041.610 PSEdition Desktop PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} BuildVersion 10.0.19041.610 CLRVersion 4.0.30319.42000 WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1

  • ITGlueAPI - default
  • Operating System

OsName : Microsoft Windows 10 Enterprise OsOperatingSystemSKU : EnterpriseEdition OsArchitecture : 64-bit WindowsVersion : 2004 WindowsBuildLabEx : 19041.1.amd64fre.vb_release.191206-1406 OsLanguage : en-US OsMuiLanguages : {en-US}

ghost avatar Mar 25 '21 23:03 ghost

I see this is fixed in Master. Is there a schedule for when this will get published?

ghost avatar Apr 28 '21 20:04 ghost

Hello,

I am receiving this same error when executing just Get-ITGlueFlexibleAssetFields alone, alongside attempting to provide the required ID argument.

image

Am I calling the function wrong alongside this issue? Or is this issue larger than just the Get-Help response?

If this was fixed here in git, it's still not reflecting in PSGallery.

Thanks guys!

sid-engel avatar Aug 10 '21 13:08 sid-engel

I know that the problem is is because you cannot use [Nullable[String]]$variable_name but I never understood why.

Nullable<T> Struct takes a value type variable and System.String is a reference type variable. https://docs.microsoft.com/en-us/dotnet/api/system.nullable-1?view=net-5.0

Type Parameters

T The underlying value type of the Nullable<T> generic type.

https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/data-types/value-types-and-reference-types

There are two kinds of types in Visual Basic: reference types and value types. Variables of reference types store references to their data (objects), while variables of value types directly contain their data.

Reference Types

A reference type stores a reference to its data. Reference types include the following:

  • String

 

In short, [Nullable[String]]$filter_name = $null -> [String]$filter_name = $null should be enough, and = $null might not even be necessary `.

function Test-Function {
    param(
        $variable
    )

    if($variable) {
        Write-Host ('$s is {0}.' -f $variable)
    }
}

Test-Function                      # No output
Test-Function -variable "a string" # Outputs "$s is a string."

ecspresso avatar Aug 11 '21 08:08 ecspresso

I have already fixed this issue a few months ago in #117 but I forgot to change the module version. I have created a PR to correct the version (latest should be 2.1.1, published is 2.1.0) but I cannot merge or publish to PowerShell Gallery.

ecspresso avatar Aug 11 '21 08:08 ecspresso

Using the changes in the latest code (copied manually from the site) I get image

This is lines 47 and 50 having [Nullable[String]] Replaced by [String] as the current code shows, not the module itself which is a release behind it looks like.

mrobinson-ws avatar Jun 24 '22 21:06 mrobinson-ws

Hey all - just as an update, this should be taken care of in v2.2.0 (released this week). Please feel free to open a new issue if that is not the case.

Cheers!

CalebAlbers avatar Dec 07 '22 04:12 CalebAlbers