Skip to content

Rewrite cmdlet Add-IshBackgroundTask to not use Microsoft.IdentityModel.Tokens.CollectionUtilities.IsNullOrEmpty extension method #216

@ddemeyer

Description

@ddemeyer

Problem
When executing Add-IshBackgroundTask on a PowerShell runtime where Microsoft.IdentityModel.Tokens.dll of version 8.0.0 or higher was loaded you will get

MethodAccessException: Attempt by method ‘Trisoft.ISHRemote.Cmdlets.BackgroundTask.AddIshBackgroundTask.EndProcessing()’ to access method ‘Microsoft.IdentityModel.Tokens.CollectionUtilities.IshNullOrEmpty<System.Char>(System.Collections.Generic.IEnumberable’1<Char>)’ failed.

Analysis...
First google hit https://adamstorr.co.uk/blog/microsoft.identitymodel.tokens-has-finally-fixed-isnullorempty-foobar/ is titled “A long running frustration with the Microsoft.IdentityModel.Tokens package has finally been fixed. And it's a breaking change!”

The code below, inside assembly Microsoft.IdentityModel.Tokens.dll is made private since v8.0.0, while it was public before - a breaking change. It is only used in ISHRemote Add-IshBackgroundTask since #193

public static class CollectionUtilities
{
    public static bool IsNullOrEmpty<T>(this IEnumerable<T> enumerable)
    {
        if (enumerable != null)
        {
            return !enumerable.Any();
        }
        return true;
    }
}

Also mentioned on
https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/issues/2651 fixed since Microsoft.IdentityModel.Tokens 8.0.0

Fix...

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions