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...
Problem
When executing
Add-IshBackgroundTaskon a PowerShell runtime whereMicrosoft.IdentityModel.Tokens.dllof version 8.0.0 or higher was loaded you will getAnalysis...
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.dllis madeprivatesince v8.0.0, while it waspublicbefore - a breaking change. It is only used in ISHRemoteAdd-IshBackgroundTasksince #193Also mentioned on
https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/issues/2651 fixed since Microsoft.IdentityModel.Tokens 8.0.0
Fix...
if (EventDescription.IsNullOrEmpty())to no longer use the extension method, which was an unnecessary usage any way. Switching to https://learn.microsoft.com/en-us/dotnet/api/system.string.isnullorempty?view=netframework-4.8