When using the PureStorage PowerShellSDK v2 that was installed using the MSI installer, OAuth authentication may fail with an error such as below for the Newtonsoft.dll.
VERBOSE: PureStorage.Rest Verbose: 13 : 2023-10-27T18:21:04.4713973Z Error: Exception System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.
File name: 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
at JWT.Serializers.JsonNetSerializer..ctor()
at PureStorage.Rest.TokenManager.newToken(IDictionary`2 headers, JwtPayload payload, IJwtAlgorithm algorithm)
at PureStorage.Rest.TokenManager.generateIdToken(IEnumerable`1 claims, IDictionary`2 headers, PureCertInfo pureCertInfo)
at PureStorage.Rest.TokenManager.refreshIdToken()
at PureStorage.Rest.TokenManager.refreshAccessToken(Rest2Api rest2ApiWrapper, Configuration configuration)
at PureStorage.Rest.PureClient.DoRetries[T](String method, String path, String apiVersion, Func`1 retriable)
This does not apply to the module if installed from the PowerShell Gallery via the
Install-Module command. It only applies when using the MSI installer.
Applies to
FlashArray API, PowerShell SDK v2 MSI installer
Answer
This error is due to the issue that .Net v4 is unable of handling assembly binding for Newtonsoft libraries correctly.
To fix this, please using the following steps:
- Find location for .NET configuration (machine.config) using:
- [System.Runtime.InteropServices.RuntimeEnvironment]::SystemConfigurationFile
- Update machine config under configuration>runtime/assemblyBinding, and add redirect config for Newtonsoft.Json
- See example below:
<runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="13.0.0.0" /> </dependentAssembly> </assemblyBinding> </runtime> - Restart the PowerShell session for change to take effect