msgraph-sdk-powershell
msgraph-sdk-powershell copied to clipboard
Connect-ExchangeOnline: Method not found: 'Microsoft.Identity.Client.PublicClientApplicationBuilder
Describe the bug
I am not sure if the issue is at the right location here but ExchangeOnlineManagement is not on GitHub unfortunately.
When calling Connect-ExchangeOnline after you called Connect-AzAccount you get the error:
OperationStopped: Method not found: 'Microsoft.Identity.Client.PublicClientApplicationBuilder
Microsoft.Identity.Client.Broker.BrokerExtension.WithBroker(Microsoft.Identity.Client.PublicClientApplicationBuilder, Microsoft.Identity.Client.BrokerOptions)'.
I have described a workaround in the discussion https://github.com/microsoftgraph/msgraph-sdk-powershell/discussions/3254#discussioncomment-13328568.
Expected behavior
Connect-ExchangeOnline works without throwing errors even if the module Az.Accounts is imported.
How to reproduce
Install-Module Az.Accounts -Scope AllUsers -Force
Install-Module ExchangeOnlineManagement -Scope AllUsers -Force
Connect-AzAccount
Connect-Connect-ExchangeOnline #fails
SDK Version
ExchangeOnlineManagement 3.7.2
Latest version known to work for scenario above?
ExchangeOnlineManagement 3.7.1
Known Workarounds
Import-Module -Name ExchangeOnlineManagement
try
{
Connect-ExchangeOnline -UserPrincipalName [email protected] -Credential $dummyCred | Out-Null
}
catch
{
# Exception is expected
}
Debug output
VERBOSE: Returning precomputed version info: 3.8.0
VERBOSE: ModuleVersion: 3.8.0
VERBOSE: ConnectionContext Removed
OperationStopped: Method not found: 'Microsoft.Identity.Client.PublicClientApplicationBuilder
Microsoft.Identity.Client.Broker.BrokerExtension.WithBroker(Microsoft.Identity.Client.PublicClientApplicationBuilder,
Microsoft.Identity.Client.BrokerOptions)'.
Configuration
Name Value
---- -----
PSVersion 7.4.4
PSEdition Core
GitCommitId 7.4.4
OS Microsoft Windows 10.0.20348
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Other information
No response
We are also experiencing this issue when loading the Graph PowerShell SDK modules in our scripts prior to the ExchangeOnlineManagement module using the #Requires statement (can be repo’d interactively using Import-Module cmdlet). There was a similar issue last year (see: https://github.com/microsoftgraph/msgraph-sdk-powershell/issues/2803) and until Microsoft fixed it in ExchangeOnlineManagement module version 3.6.0, the workaround was to load the Graph modules before ExchangeOnlineManagement. Now the workaround for this new issue has been to load ExchangeOnlineManagement before the Graph modules. It’s ridiculous that Microsoft keeps introducing these bugs. Where is the regression and compatibility testing for these modules.
Example:
Windows 11 PowerShell 5.1 ExchangeOnlineManagement version 3.8.0 Microsoft.Graph version 2.28.0
Import-Module Microsoft.Graph.Authentication
Import-Module Microsoft.Graph.Users
Import-Module ExchangeOnlineManagement
Connect-ExchangeOnline -Credential $EXO_Cred -Verbose
VERBOSE: Computed version info: 3.8.0
VERBOSE: ModuleVersion: 3.8.0
VERBOSE: ConnectionContext Removed
Method not found: 'Microsoft.Identity.Client.PublicClientApplicationBuilder
Microsoft.Identity.Client.Broker.BrokerExtension.WithBroker(Microsoft.Identity.Client.PublicClientApplicationBuilder, Microsoft.Identity.Client.BrokerOptions)'.
At C:\Program Files\WindowsPowerShell\Modules\ExchangeOnlineManagement\3.8.0\netFramework\ExchangeOnlineManagement.psm1:754 char:21
+ throw $_.Exception.InnerException;
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], MissingMethodException
+ FullyQualifiedErrorId : Method not found: 'Microsoft.Identity.Client.PublicClientApplicationBuilder Microsoft.Identity.Client.Broker.BrokerExtension.WithBroker(Mic
rosoft.Identity.Client.PublicClientApplicationBuilder, Microsoft.Identity.Client.BrokerOptions)'.
I have this issue in both PowerShell 7.x and PowerShell 5.1...
5.1 Error:
Method not found: 'Microsoft.Identity.Client.PublicClientApplicationBuilder
Microsoft.Identity.Client.Broker.BrokerExtension.WithBroker(Microsoft.Identity.Client.PublicClientApplicationBuilder,
Microsoft.Identity.Client.BrokerOptions)'.
At .\Modules\ExchangeOnlineManagement\3.8.0\netFramework\ExchangeOnli
neManagement.psm1:754 char:21
+ throw $_.Exception.InnerException;
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], MissingMethodException
+ FullyQualifiedErrorId : Method not found: 'Microsoft.Identity.Client.PublicClientApplicationBuilder Microsoft.Id
entity.Client.Broker.BrokerExtension.WithBroker(Microsoft.Identity.Client.PublicClientApplicationBuilder, Microsof
t.Identity.Client.BrokerOptions)'.
7.x Error:
OperationStopped: Could not load file or assembly
'.\PowerShell\Modules\ExchangeOnlineManagement\3.8.0\netCore\Microsoft.Identity.Client.d
ll'. The located assembly's manifest definition does not match the assembly reference. (0x80131040)
I've noted the problem to the EXO module team. They have several issues with the EXO 3.8 module that need to be fixed.
On my side I get this with Exchange module loaded last and doing Connect
Could not load type | 'Microsoft.Identity.Client.BaseAbstractApplicationBuilder1' from assembly 'Microsoft.Identity.Client,
| Version=4.47.2.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae'`
On 5.1 I get:
Could not load type 'System.Diagnostics.Metrics.Meter' from assembly 'System.Diagnostics.DiagnosticSource, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
I am getting this error when doing a straight Connect-ExchangeOnline today.
Getting this issue in Powershell 7 with module version 3.8 using managed identity authentication as of Aug. 5
Could not load file of assembly 'Microsoft.OData.Core, Version=7.21.3.0....' Could not find or load a specific file. (0x809131621).
Same here, however changing the import order works as a cheap workaround 🛠️
Not working:
Import-Module Microsoft.Graph.Authentication
Connect-MgGraph ....
$ProxyOptions = New-PSSessionOption -ProxyAccessType AutoDetect
Import-Module ExchangeOnlineManagement
Connect-ExchangeOnline -PSSessionOption $ProxyOptions
But this works without any problems for us:
$ProxyOptions = New-PSSessionOption -ProxyAccessType AutoDetect
Import-Module ExchangeOnlineManagement
Connect-ExchangeOnline -PSSessionOption $ProxyOptions
Import-Module Microsoft.Graph.Authentication
Connect-MgGraph ....
However one of my colleagues then (after changing the order) had another strange problem, which I'm still unsure to what it is really related: Within VS-Code it still doesn't work, within a standalone powershell-window it does work. And to add some more fun to this: For 2 of us this problem so far did not happen at all, while one colleague had it immediately after updating the modules 💃
We're tracking this issue actively with the EXO team and will use #3394 as the work item to report status on
Closing this as a duplicate