msgraph-sdk-powershell icon indicating copy to clipboard operation
msgraph-sdk-powershell copied to clipboard

Connect-MgGraph: Could not load file or assembly 'Microsoft.Identity.Client, Version=4.23.0.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae'. Could not find or load a specific file. (0x80131621) when az.keyvault is imported

Open larsmaes opened this issue 5 years ago • 5 comments

Reproduction Steps:

install-module az.keyvault
install-module microsoft.graph

import-module az.keyvault

connect-mggraph

Connect-MgGraph: Could not load file or assembly 'Microsoft.Identity.Client, Version=4.23.0.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae'. Could not find or load a specific file. (0x80131621)

Versions:

Script     2.2.4                 Az.Accounts                         {Add-AzEnvironment, Clear-AzContext, Clear-AzDefa…
Script     3.3.1                 az.keyvault                         {Add-AzKeyVaultCertificate, Add-AzKeyVaultCertifi…
Script     1.3.0                 Microsoft.Graph.Authentication      {Add-MgEnvironment, Connect-MgGraph, Disconnect-M…

get-host

Name             : ConsoleHost
Version          : 7.1.1
InstanceId       : eb501ccc-8eef-499b-ac95-086ddc7ea61c
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : nl-NL
CurrentUICulture : nl-NL
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

larsmaes avatar Jan 29 '21 14:01 larsmaes

Same here. Yesterday things were working. Did something significant change in version 1.3.0?

Stack Trace: 2021-01-29T19:12:10.131 [Error] ERROR: Could not load file or assembly 'Microsoft.Identity.Client, Version=4.23.0.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae'. Could not find or load a specific file. (0x80131621)Exception :Type : System.IO.FileLoadExceptionMessage : Could not load file or assembly 'Microsoft.Identity.Client, Version=4.23.0.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae'. Could not find or load a specific file. (0x80131621)FileName : Microsoft.Identity.Client, Version=4.23.0.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8aeTargetSite :Name : MoveNextDeclaringType : Microsoft.Graph.PowerShell.Authentication.Cmdlets.ConnectMgGraph+d__45, Microsoft.Graph.Authentication, Version=1.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35MemberType : MethodModule : Microsoft.Graph.Authentication.dllStackTrace :at Microsoft.Graph.PowerShell.Authentication.Cmdlets.ConnectMgGraph.ProcessRecordAsync()at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)at Microsoft.Graph.PowerShell.Authentication.Cmdlets.ConnectMgGraph.ProcessRecordAsync()at Microsoft.Graph.PowerShell.Authentication.Cmdlets.ConnectMgGraph.ProcessRecord()InnerException :Type : System.IO.FileLoadExceptionMessage : Could not load file or assembly 'Microsoft.Identity.Client, Version=4.23.0.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae'.TargetSite :Name : LoadFromPathDeclaringType : System.Runtime.Loader.AssemblyLoadContextMemberType : MethodModule : System.Private.CoreLib.dllStackTrace :at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly)at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)at System.Reflection.Assembly.LoadFrom(String assemblyFile)at System.Reflection.Assembly.LoadFromResolveHandler(Object sender, ResolveEventArgs args)at System.Runtime.Loader.AssemblyLoadContext.InvokeResolveEvent(ResolveEventHandler eventHandler, RuntimeAssembly assembly, String name)at System.Runtime.Loader.AssemblyLoadContext.OnAssemblyResolve(RuntimeAssembly assembly, String assemblyFullName)Source : System.Private.CoreLibHResult : -2146232799Source : Microsoft.Graph.AuthenticationHResult : -2146232799CategoryInfo : NotSpecified: (:) [Connect-MgGraph], FileLoadExceptionFullyQualifiedErrorId : Microsoft.Graph.PowerShell.Authentication.Cmdlets.ConnectMgGraphInvocationInfo :MyCommand : Connect-MgGraphScriptLineNumber : 46OffsetInLine : 1HistoryId : 1ScriptName : D:\home\site\wwwroot\profile.ps1Line : Connect-Graph -AccessToken $global:token.AccessTokenPositionMessage : At D:\home\site\wwwroot\profile.ps1:46 char:1+ Connect-Graph -AccessToken $global:token.AccessToken+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~PSScriptRoot : D:\home\site\wwwrootPSCommandPath : D:\home\site\wwwroot\profile.ps1InvocationName : Connect-GraphCommandOrigin : InternalScriptStackTrace : at , D:\home\site\wwwroot\profile.ps1: line 46PipelineIterationInfo :Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException : Result: ERROR: Could not load file or assembly 'Microsoft.Identity.Client, Version=4.23.0.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae'. Could not find or load a specific file. (0x80131621)Exception :Type : System.IO.FileLoadExceptionMessage : Could not load file or assembly 'Microsoft.Identity.Client, Version=4.23.0.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae'. Could not find or load a specific file. (0x80131621)FileName : Microsoft.Identity.Client, Version=4.23.0.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8aeTargetSite :Name : MoveNextDeclaringType : Microsoft.Graph.PowerShell.Authentication.Cmdlets.ConnectMgGraph+d__45, Microsoft.Graph.Authentication, Version=1.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35MemberType : MethodModule : Microsoft.Graph.Authentication.dllStackTrace :at Microsoft.Graph.PowerShell.Authentication.Cmdlets.ConnectMgGraph.ProcessRecordAsync()at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)at Microsoft.Graph.PowerShell.Authentication.Cmdlets.ConnectMgGraph.ProcessRecordAsync()at Microsoft.Graph.PowerShell.Authentication.Cmdlets.ConnectMgGraph.ProcessRecord()InnerException :Type : System.IO.FileLoadExceptionMessage : Could not load file or assembly 'Microsoft.Identity.Client, Version=4.23.0.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae'.TargetSite :Name : LoadFromPathDeclaringType : System.Runtime.Loader.AssemblyLoadContextMemberType : MethodModule : System.Private.CoreLib.dllStackTrace :at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly)at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)at System.Reflection.Assembly.LoadFrom(String assemblyFile)at System.Reflection.Assembly.LoadFromResolveHandler(Object sender, ResolveEventArgs args)at System.Runtime.Loader.AssemblyLoadContext.InvokeResolveEvent(ResolveEventHandler eventHandler, RuntimeAssembly assembly, String name)at System.Runtime.Loader.AssemblyLoadContext.OnAssemblyResolve(RuntimeAssembly assembly, String assemblyFullName)Source : System.Private.CoreLibHResult : -2146232799Source : Microsoft.Graph.AuthenticationHResult : -2146232799CategoryInfo : NotSpecified: (:) [Connect-MgGraph], FileLoadExceptionFullyQualifiedErrorId : Microsoft.Graph.PowerShell.Authentication.Cmdlets.ConnectMgGraphInvocationInfo :MyCommand : Connect-MgGraphScriptLineNumber : 46OffsetInLine : 1HistoryId : 1ScriptName : D:\home\site\wwwroot\profile.ps1Line : Connect-Graph -AccessToken $global:token.AccessTokenPositionMessage : At D:\home\site\wwwroot\profile.ps1:46 char:1+ Connect-Graph -AccessToken $global:token.AccessToken+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~PSScriptRoot : D:\home\site\wwwrootPSCommandPath : D:\home\site\wwwroot\profile.ps1InvocationName : Connect-GraphCommandOrigin : InternalScriptStackTrace : at , D:\home\site\wwwroot\profile.ps1: line 46PipelineIterationInfo :Exception: Could not load file or assembly 'Microsoft.Identity.Client, Version=4.23.0.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae'. Could not find or load a specific file. (0x80131621)Stack: at Microsoft.Graph.PowerShell.Authentication.Cmdlets.ConnectMgGraph.ProcessRecordAsync()at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)at Microsoft.Graph.PowerShell.Authentication.Cmdlets.ConnectMgGraph.ProcessRecordAsync()at Microsoft.Graph.PowerShell.Authentication.Cmdlets.ConnectMgGraph.ProcessRecord()

michaeltheyeti avatar Jan 29 '21 19:01 michaeltheyeti

This appears to be a version conflict with another module.

I implemented the following as a workaround:

Import-Module -Name Microsoft.Graph.Authentication -UseWindowsPowerShell Import-Module -Name Microsoft.Graph.Users.Actions -UseWindowsPowerShell

These are the two modules I use.

michaeltheyeti avatar Jan 29 '21 19:01 michaeltheyeti

I installed Microsoft Graph PowerShell's SDK yesterday on a new machine and had the same issue with VSCode and PowerShell 7.1.1 (it worked on PowerShell ISE with PowerShell 5.1). After restarting VSCode the error went away and was able to use Connect-MgGraph successfully.

I got the error at a later point after loading MSAL.PS, so definitely looks like a module conflict issue as @michaeltheyeti pointed out. Restarting the terminal in VSCode did the trick for me.

ATJSM avatar Jan 29 '21 19:01 ATJSM

Thanks for reporting this and sorry for the inconvenience caused.

This is indeed a dependency version conflict with az.accounts module that occurred when we bumped our version of Microsoft.Identity.Client to 4.23.0 which is higher than the one az.accounts uses (4.21.0).

We are working on a hot fix to resolve this.

peombwa avatar Jan 29 '21 20:01 peombwa

This has now been fixed and a new version has been published to PowerShell Gallery. Use Update-Module Microsoft.Graph to update to the latest version.

peombwa avatar Jan 30 '21 05:01 peombwa