Description
created powershell 7 function app,
dependencies:
'Az.Accounts' = '2.9.1'
'Microsoft.Graph' = '1.11.0'
'Az.KeyVault' = '4.6.1'
'MSAL.PS' = '4.2.1.3'
$AppId = 'xxx'
$TenantId = 'xxx'
$ClientSecret = 'xxx'
Import-Module MSAL.PS
$MsalToken = Get-MsalToken -TenantId $TenantId -ClientId $AppId -ClientSecret ($ClientSecret | ConvertTo-SecureString -AsPlainText -Force)
Connect-MgGraph -AccessToken $MsalToken.AccessToken
Error Command Connect-MgGraph and error message Could not load file or assembly 'Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. The system cannot find the file specified.
PowerShell 7 currently ships with Newtonsoft.Json 12.0.3 according to this document: https://docs.microsoft.com/en-us/powershell/scripting/dev-cross-plat/resolving-dependency-conflicts?view=powershell-7.2
#1341, this change was released with 1.11.0, but when I tried to set 'Microsoft.Graph' = '1.10.0', it failed with same error, it still tries to load Microsoft.Graph.Authentication, Version=1.11.0.0. It's probably because 1.11.0 has been installed on the machine.
So I have to use 1.9.6 as a workaround. Please help fix this issue.
[2022-08-05T09:38:28.761Z] Exception :
[2022-08-05T09:38:28.763Z] Type : System.IO.FileNotFoundException
[2022-08-05T09:38:28.766Z] Message : Could not load file or assembly 'Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. The system cannot find the file specified.
[2022-08-05T09:38:28.768Z] FileName : Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
[2022-08-05T09:38:28.771Z] TargetSite :
[2022-08-05T09:38:28.773Z] Name : MoveNext
[2022-08-05T09:38:28.775Z] DeclaringType : Microsoft.Graph.PowerShell.Authentication.Cmdlets.ConnectMgGraph+d__56, Microsoft.Graph.Authentication, Version=1.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35