(Abbreviated) Error: "Method 'get_SerializationSettings" when using new versions of Az module in VS Code (no issue in ISE) in PS 5.1
Description
When attempting to use the Connect-AzAccount command (and others) within VS Code, the following error is returned:
This article has a statement from a Microsoft rep that states that if you down grade to a version of the module that uses Az.Accounts version 2.12.1 or lower, it will work. While I have confirmed that downgrading the version does, in fact, resolve the issue, I wanted to see if we could get this tracked as a bug.
I should note that using PowerShell 7 (currently leveraging 7.4.1) in VS Code does resolve the issue, as well as using 5.1.xxx in ISE, rather than VS Code. That being said, upgrading to PS 7 is not always feasible due to environment or admin restrictions, and it sure would be nice to use VS Code rather than ISE.
Running Az on the latest version (11.4.0). Any help is appreciated.
Issue script & Debug output
Connect-AzAccount
DEBUG: Initializing ConditionalAssemblyContext. PSEdition is [Desktop]. PSVersion is [5.1.22621.2506].
DEBUG: Initializing ConditionalAssemblyProvider. AssemblyRootPath is [C:\Users\xxxxxx\Documents\WindowsPowerShell\Modules\Az.Accounts\2.16.0\StartupScripts\..\lib].
Connect-AzAccount : Method 'get_SerializationSettings' in type 'Microsoft.Azure.Management.Internal.Resources.ResourceManagementClient' from assembly
'Microsoft.Azure.PowerShell.Clients.ResourceManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.
At line:1 char:1
+ Connect-AzAccount
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Connect-AzAccount], TypeLoadException
+ FullyQualifiedErrorId : System.TypeLoadException,Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand
Environment data
Major Minor Build Revision
----- ----- ----- --------
5 1 22621 2506
Module versions
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 2.16.0 Az.Accounts {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear-AzDefault...}
*************************************
OTHER AZs INSTALLED FOR REFERENCE:
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 2.16.0 Az.Accounts {Disable-AzDataCollection, Disable-AzContextAutosave, Enable-AzDataCollection, Enable-AzContextAutosave...}
Script 2.0.0 Az.Advisor {Disable-AzAdvisorRecommendation, Enable-AzAdvisorRecommendation, Get-AzAdvisorConfiguration, Get-AzAdvisorRecommenda...
Script 6.0.1 Az.Aks {Disable-AzAksAddOn, Enable-AzAksAddOn, Get-AzAksCluster, Get-AzAksNodePool...}
Script 1.1.4 Az.AnalysisServices {Resume-AzAnalysisServicesServer, Suspend-AzAnalysisServicesServer, Get-AzAnalysisServicesServer, Remove-AzAnalysisSe...
Script 4.0.2 Az.ApiManagement {Add-AzApiManagementApiToGateway, Add-AzApiManagementApiToProduct, Add-AzApiManagementProductToGroup, Add-AzApiManage...
Script 1.0.0 Az.App {Disable-AzContainerAppRevision, Enable-AzContainerAppRevision, Get-AzContainerApp, Get-AzContainerAppAuthConfig...}
Script 1.3.0 Az.AppConfiguration {Get-AzAppConfigurationStore, Get-AzAppConfigurationStoreKey, New-AzAppConfigurationStore, New-AzAppConfigurationStor...
Script 2.2.3 Az.ApplicationInsights {Get-AzApplicationInsights, Get-AzApplicationInsightsApiKey, Get-AzApplicationInsightsContinuousExport, Get-AzApplica...
Script 1.0.0 Az.ArcResourceBridge {Get-AzArcResourceBridge, Get-AzArcResourceBridgeApplianceCredential, Get-AzArcResourceBridgeCredential, Get-AzArcRes...
Script 2.0.0 Az.Attestation {Get-AzAttestationPolicy, Set-AzAttestationPolicy, Reset-AzAttestationPolicy, Get-AzAttestationPolicySigners...}
Script 1.0.0 Az.Automanage {Get-AzAutomanageBestPractice, Get-AzAutomanageConfigProfile, Get-AzAutomanageConfigProfileAssignment, Get-AzAutomana...
Script 1.10.0 Az.Automation {Export-AzAutomationDscConfiguration, Export-AzAutomationDscNodeReportContent, Export-AzAutomationRunbook, Get-AzAuto...
Script 3.5.0 Az.Batch {Remove-AzBatchAccount, Get-AzBatchAccount, Get-AzBatchAccountKey, New-AzBatchAccount...}
Script 2.0.3 Az.Billing {Get-AzBillingInvoice, Get-AzBillingPeriod, Get-AzEnrollmentAccount, Get-AzConsumptionBudget...}
Script 3.1.2 Az.Cdn {Clear-AzCdnEndpointContent, Clear-AzFrontDoorCdnEndpointContent, Disable-AzCdnCustomDomainCustomHttps, Enable-AzCdnC...
Script 2.0.0 Az.CloudService {Get-AzCloudService, Get-AzCloudServiceInstanceView, Get-AzCloudServiceNetworkInterface, Get-AzCloudServiceOSFamily...}
Script 1.14.1 Az.CognitiveServices {Get-AzCognitiveServicesAccount, Get-AzCognitiveServicesAccountKey, Get-AzCognitiveServicesAccountSku, Get-AzCognitiv...
Script 7.1.2 Az.Compute {Add-AzImageDataDisk, Add-AzVhd, Add-AzVMAdditionalUnattendContent, Add-AzVMDataDisk...}
Script 1.0.0 Az.ConfidentialLedger {Get-AzConfidentialLedger, New-AzConfidentialLedger, New-AzConfidentialLedgerAADBasedSecurityPrincipalObject, New-AzC...
Script 4.0.0 Az.ContainerInstance {Add-AzContainerInstanceOutput, Get-AzContainerGroup, Get-AzContainerInstanceCachedImage, Get-AzContainerInstanceCapa...
Script 4.1.3 Az.ContainerRegistry {Connect-AzContainerRegistry, Get-AzContainerRegistryManifest, Get-AzContainerRegistryRepository, Get-AzContainerRegi...
Script 1.14.1 Az.CosmosDB {Get-AzCosmosDBAccount, Get-AzCosmosDBAccountKey, Get-AzCosmosDBCassandraKeyspace, Get-AzCosmosDBCassandraKeyspaceThr...
Script 1.1.0 Az.DataBoxEdge {Get-AzDataBoxEdgeJob, Get-AzDataBoxEdgeDevice, Invoke-AzDataBoxEdgeDevice, New-AzDataBoxEdgeDevice...}
Script 1.7.1 Az.Databricks {Get-AzDatabricksAccessConnector, Get-AzDatabricksOutboundNetworkDependenciesEndpoint, Get-AzDatabricksVNetPeering, G...
Script 1.18.2 Az.DataFactory {Add-AzDataFactoryV2DataFlowDebugSessionPackage, Add-AzDataFactoryV2TriggerSubscription, Get-AzDataFactory, Get-AzDat...
Script 1.0.3 Az.DataLakeAnalytics {Get-AzDataLakeAnalyticsDataSource, New-AzDataLakeAnalyticsCatalogCredential, Remove-AzDataLakeAnalyticsCatalogCreden...
Script 1.3.0 Az.DataLakeStore {Get-AzDataLakeStoreTrustedIdProvider, Remove-AzDataLakeStoreTrustedIdProvider, Remove-AzDataLakeStoreFirewallRule, S...
Script 2.2.0 Az.DataProtection {Backup-AzDataProtectionBackupInstanceAdhoc, Edit-AzDataProtectionPolicyRetentionRuleClientObject, Edit-AzDataProtect...
Script 1.0.1 Az.DataShare {New-AzDataShareAccount, Get-AzDataShareAccount, Remove-AzDataShareAccount, New-AzDataShare...}
Script 4.3.0 Az.DesktopVirtualization {Disconnect-AzWvdUserSession, Expand-AzWvdMsixImage, Get-AzWvdApplication, Get-AzWvdApplicationGroup...}
Script 1.1.0 Az.DevCenter {Deploy-AzDevCenterUserEnvironment, Get-AzDevCenterAdminAttachedNetwork, Get-AzDevCenterAdminCatalog, Get-AzDevCenter...
Script 1.0.2 Az.DevTestLabs {Get-AzDtlAllowedVMSizesPolicy, Get-AzDtlAutoShutdownPolicy, Get-AzDtlAutoStartPolicy, Get-AzDtlVMsPerLabPolicy...}
Script 1.2.0 Az.Dns {Get-AzDnsRecordSet, New-AzDnsRecordConfig, Remove-AzDnsRecordSet, Set-AzDnsRecordSet...}
Script 1.0.0 Az.ElasticSan {Add-AzElasticSanVolumeGroupNetworkRule, Get-AzElasticSan, Get-AzElasticSanSkuList, Get-AzElasticSanVolume...}
Script 1.6.0 Az.EventGrid {New-AzEventGridTopic, Get-AzEventGridTopic, Set-AzEventGridTopic, New-AzEventGridTopicKey...}
Script 4.2.0 Az.EventHub {New-AzEventHubAuthorizationRuleSASToken, Approve-AzEventHubPrivateEndpointConnection, Deny-AzEventHubPrivateEndpoint...
Script 1.10.0 Az.FrontDoor {New-AzFrontDoor, Get-AzFrontDoor, Set-AzFrontDoor, Remove-AzFrontDoor...}
Script 4.0.7 Az.Functions {Get-AzFunctionApp, Get-AzFunctionAppAvailableLocation, Get-AzFunctionAppPlan, Get-AzFunctionAppSetting...}
Script 6.1.0 Az.HDInsight {Add-AzHDInsightClusterIdentity, Add-AzHDInsightComponentVersion, Add-AzHDInsightConfigValue, Add-AzHDInsightMetastor...
Script 2.0.0 Az.HealthcareApis {Get-AzHealthcareApisService, Get-AzHealthcareApisWorkspace, Get-AzHealthcareDicomService, Get-AzHealthcareFhirDestin...
Script 2.7.5 Az.IotHub {Add-AzIotHubKey, Get-AzIotHubEventHubConsumerGroup, Get-AzIotHubConnectionString, Get-AzIotHubJob...}
Script 5.2.1 Az.KeyVault {Add-AzKeyVaultCertificate, Add-AzKeyVaultCertificateContact, Add-AzKeyVaultKey, Add-AzKeyVaultManagedStorageAccount...}
Script 2.3.0 Az.Kusto {Add-AzKustoClusterLanguageExtension, Add-AzKustoDatabasePrincipal, Get-AzKustoAttachedDatabaseConfiguration, Get-AzK...
Script 1.0.0 Az.LoadTesting {Get-AzLoad, New-AzLoad, Remove-AzLoad, Update-AzLoad}
Script 1.5.1 Az.LogicApp {Get-AzIntegrationAccount, Get-AzIntegrationAccountAgreement, Get-AzIntegrationAccountAssembly, Get-AzIntegrationAcco...
Script 1.1.3 Az.MachineLearning {Move-AzMlCommitmentAssociation, Get-AzMlCommitmentAssociation, Get-AzMlCommitmentPlanUsageHistory, Remove-AzMlCommit...
Script 1.0.0 Az.MachineLearningServices {Get-AzMLServiceQuota, Get-AzMLServiceUsage, Get-AzMLServiceVMSize, Get-AzMLWorkspace...}
Script 1.4.1 Az.Maintenance {Get-AzApplyUpdate, Get-AzConfigurationAssignment, Get-AzMaintenanceConfiguration, Get-AzMaintenanceUpdate...}
Script 1.2.0 Az.ManagedServiceIdentity {Get-AzSystemAssignedIdentity, Get-AzUserAssignedIdentity, Get-AzUserAssignedIdentityAssociatedResource, New-AzUserAs...
Script 3.0.0 Az.ManagedServices {Get-AzManagedServicesAssignment, Get-AzManagedServicesDefinition, Get-AzManagedServicesMarketplaceDefinition, New-Az...
Script 2.0.0 Az.MarketplaceOrdering {Get-AzMarketplaceTerms, Invoke-AzMarketplaceSignTerms, Set-AzMarketplaceTerms, Stop-AzMarketplaceTerms}
Script 1.1.2 Az.Media {Sync-AzMediaServiceStorageKey, Set-AzMediaServiceKey, Get-AzMediaServiceKey, Get-AzMediaServiceNameAvailability...}
Script 2.3.0 Az.Migrate {Get-AzMigrateDiscoveredServer, Get-AzMigrateHCIJob, Get-AzMigrateHCIReplicationFabric, Get-AzMigrateHCIServerReplica...
Script 5.1.0 Az.Monitor {Add-AzLogProfile, Add-AzMetricAlertRule, Add-AzMetricAlertRuleV2, Add-AzWebtestAlertRule...}
Script 1.1.1 Az.MySql {Get-AzMySqlConfiguration, Get-AzMySqlConnectionString, Get-AzMySqlFirewallRule, Get-AzMySqlFlexibleServer...}
Script 7.4.0 Az.Network {Add-AzApplicationGatewayAuthenticationCertificate, Add-AzApplicationGatewayBackendAddressPool, Add-AzApplicationGate...
Script 1.0.0 Az.NetworkCloud {Deploy-AzNetworkCloudCluster, Disable-AzNetworkCloudStorageApplianceRemoteVendorManagement, Enable-AzNetworkCloudSto...
Script 1.0.0 Az.Nginx {Get-AzNginxCertificate, Get-AzNginxConfiguration, Get-AzNginxDeployment, New-AzNginxCertificate...}
Script 1.1.2 Az.NotificationHubs {Get-AzNotificationHub, Get-AzNotificationHubAuthorizationRule, Get-AzNotificationHubListKey, Get-AzNotificationHubPN...
Script 3.2.0 Az.OperationalInsights {New-AzOperationalInsightsAzureActivityLogDataSource, New-AzOperationalInsightsCustomLogDataSource, Disable-AzOperati...
Script 1.6.4 Az.PolicyInsights {Get-AzPolicyEvent, Get-AzPolicyState, Get-AzPolicyStateSummary, Get-AzPolicyRemediation...}
Script 1.1.0 Az.PostgreSql {Get-AzPostgreSqlConfiguration, Get-AzPostgreSqlConnectionString, Get-AzPostgreSqlFirewallRule, Get-AzPostgreSqlFlexi...
Script 2.0.0 Az.PowerBIEmbedded {Resume-AzPowerBIEmbeddedCapacity, Suspend-AzPowerBIEmbeddedCapacity, Get-AzPowerBIEmbeddedCapacity, Remove-AzPowerBI...
Script 1.0.4 Az.PrivateDns {Get-AzPrivateDnsZone, Remove-AzPrivateDnsZone, Set-AzPrivateDnsZone, New-AzPrivateDnsZone...}
Script 6.7.1 Az.RecoveryServices {Add-AzRecoveryServicesAsrReplicationProtectedItemDisk, Backup-AzRecoveryServicesBackupItem, Copy-AzRecoveryServicesV...
Script 1.9.0 Az.RedisCache {Export-AzRedisCache, Get-AzRedisCache, Get-AzRedisCacheFirewallRule, Get-AzRedisCacheKey...}
Script 1.2.0 Az.RedisEnterpriseCache {Export-AzRedisEnterpriseCache, Get-AzRedisEnterpriseCache, Get-AzRedisEnterpriseCacheDatabase, Get-AzRedisEnterprise...
Script 2.0.0 Az.Relay {Get-AzRelayAuthorizationRule, Get-AzRelayHybridConnection, Get-AzRelayKey, Get-AzRelayNamespace...}
Script 1.2.0 Az.ResourceMover {Add-AzResourceMoverMoveResource, Get-AzResourceMoverMoveCollection, Get-AzResourceMoverMoveResource, Get-AzResourceM...
Script 6.16.0 Az.Resources {Export-AzResourceGroup, Export-AzTemplateSpec, Get-AzDenyAssignment, Get-AzDeployment...}
Script 1.6.0 Az.Security {Add-AzSecurityAdaptiveNetworkHardening, Add-AzSecuritySqlVulnerabilityAssessmentBaseline, Confirm-AzSecurityAutomati...
Script 3.1.1 Az.SecurityInsights {Get-AzSentinelAlertRule, Get-AzSentinelAlertRuleAction, Get-AzSentinelAlertRuleTemplate, Get-AzSentinelAutomationRul...
Script 3.0.0 Az.ServiceBus {New-AzServiceBusAuthorizationRuleSASToken, Test-AzServiceBusNameAvailability, Approve-AzServiceBusPrivateEndpointCon...
Script 3.3.2 Az.ServiceFabric {Add-AzServiceFabricClientCertificate, Add-AzServiceFabricManagedClusterClientCertificate, Add-AzServiceFabricManaged...
Script 2.0.0 Az.SignalR {New-AzSignalR, Get-AzSignalR, Get-AzSignalRKey, New-AzSignalRKey...}
Script 4.14.0 Az.Sql {Add-AzSqlDatabaseToFailoverGroup, Add-AzSqlElasticJobStep, Add-AzSqlElasticJobTarget, Add-AzSqlInstanceKeyVaultKey...}
Script 2.2.0 Az.SqlVirtualMachine {Get-AzAvailabilityGroupListener, Get-AzSqlVM, Get-AzSqlVMGroup, Invoke-AzRedeploySqlVM...}
Script 2.3.1 Az.StackHCI {Add-AzStackHCIVMAttestation, Disable-AzStackHCIAttestation, Disable-AzStackHCIRemoteSupport, Enable-AzStackHCIAttest...
Script 1.0.1 Az.StackHCIVM {Add-AzStackHCIVMVirtualMachineDataDisk, Add-AzStackHCIVMVirtualMachineNetworkInterface, Get-AzStackHCIVMImage, Get-A...
Script 6.1.2 Az.Storage {Add-AzRmStorageContainerLegalHold, Add-AzStorageAccountManagementPolicyAction, Add-AzStorageAccountNetworkRule, Clos...
Script 1.3.0 Az.StorageMover {Get-AzStorageMover, Get-AzStorageMoverAgent, Get-AzStorageMoverEndpoint, Get-AzStorageMoverJobDefinition...}
Script 2.1.1 Az.StorageSync {Get-AzStorageSyncCloudEndpoint, Get-AzStorageSyncGroup, Get-AzStorageSyncServer, Get-AzStorageSyncServerEndpoint...}
Script 2.0.0 Az.StreamAnalytics {Get-AzStreamAnalyticsCluster, Get-AzStreamAnalyticsClusterStreamingJob, Get-AzStreamAnalyticsDefaultFunctionDefiniti...
Script 1.0.0 Az.Support {Get-AzSupportService, Get-AzSupportProblemClassification, Get-AzSupportTicket, Get-AzSupportTicketCommunication...}
Script 3.0.5 Az.Synapse {Add-AzSynapseDataFlowDebugSessionPackage, Add-AzSynapseTriggerSubscription, Clear-AzSynapseSqlPoolVulnerabilityAsses...
Script 1.2.2 Az.TrafficManager {Add-AzTrafficManagerCustomHeaderToEndpoint, Remove-AzTrafficManagerCustomHeaderFromEndpoint, Add-AzTrafficManagerCus...
Script 3.2.0 Az.Websites
Error output
Resolve-AzError
Resolve-AzError : Method 'get_SerializationSettings' in type 'Microsoft.Azure.Management.Internal.Resources.ResourceManagementClient' from assembly
'Microsoft.Azure.PowerShell.Clients.ResourceManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.
At line:1 char:1
+ Resolve-AzError
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Resolve-AzError], TypeLoadException
+ FullyQualifiedErrorId : System.TypeLoadException,Microsoft.Azure.Commands.Profile.Errors.ResolveError
It happens not only with the az-connect command, but also when trying to retrieve the az-session context, and with almost any az command you try to execute even if the client is not logged in. I detail an example below.
PS C:\Userserspedro.fernandez-montOneDrive - GFI Documents - WindowsPowerShellScripts> $context = Get-AzContext
Get-AzContext : The 'get_SerializationSettings' method on the 'Microsoft.Azure.Management.Internal.Resources.ResourceManagementClient' type of the 'Microsoft.Azure.Management.Internal.Resources.ResourceManagementClient' assembly.
assembly 'Microsoft.Azure.PowerShell.Clients.ResourceManager, Version=1.0.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an
implementation.
Inline: 1 Character: 12
- $context = Get-AzContext
-
+ CategoryInfo : NotSpecified: (:) [Get-AzContext], TypeLoadException + FullyQualifiedErrorId : System.TypeLoadException,Microsoft.Azure.Commands.Profile.GetAzureRMContextCommand.
Translated with DeepL.com (free version)
I'm facing the similar issue when I moved from older laptop to new laptop with new setup for VSCode
Connect-AzAccount
Connect-AzAccount : Method 'get_SerializationSettings' in type 'Microsoft.Azure.Management.Internal.Resources.ResourceManagementClient' from assembly
'Microsoft.Azure.PowerShell.Clients.ResourceManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf38756ad364e35' does not have an implementation.
At line:1 char:1
+ Connect-AzAccount
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Connect-AzAccount], TypeLoadException
+ FullyQualifiedErrorId : System.TypeLoadException,Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand
We have Azure Automation Hybrid Runbooks and they are failing because of this.
I'm facing the similar issue when I moved from older laptop to new laptop with new setup for VSCode
Connect-AzAccount
Connect-AzAccount : Method 'get_SerializationSettings' in type 'Microsoft.Azure.Management.Internal.Resources.ResourceManagementClient' from assembly 'Microsoft.Azure.PowerShell.Clients.ResourceManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf38756ad364e35' does not have an implementation. At line:1 char:1 + Connect-AzAccount + ~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Connect-AzAccount], TypeLoadException + FullyQualifiedErrorId : System.TypeLoadException,Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand
I had lower version (5.0) of PowerShell in my laptop, so I had to install latest version which fixed the issue.
I am facing the same issue if I use powershell 5.1 within VSCode. If I use powershell 7.X then its fine but I would prefer to stick with PS 5.1
`Connect-AzAccount
Connect-AzAccount : Method 'get_SerializationSettings' in type 'Microsoft.Azure.Management.Internal.Resources.ResourceManagementClient' from assembly
'Microsoft.Azure.PowerShell.Clients.ResourceManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.
At line:1 char:1
+ Connect-AzAccount
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Connect-AzAccount], TypeLoadException
+ FullyQualifiedErrorId : System.TypeLoadException,Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand`
I am facing the same issue if I use powershell 5.1 within VSCode. If I use powershell 7.X then its fine but I would prefer to stick with PS 5.1
`Connect-AzAccount Connect-AzAccount : Method 'get_SerializationSettings' in type 'Microsoft.Azure.Management.Internal.Resources.ResourceManagementClient' from assembly 'Microsoft.Azure.PowerShell.Clients.ResourceManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation. At line:1 char:1 + Connect-AzAccount + ~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Connect-AzAccount], TypeLoadException + FullyQualifiedErrorId : System.TypeLoadException,Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand`
In that case 5.1 supported modules should be used for it in this case Az.Accounts module
Same issue as here: https://github.com/Azure/azure-powershell/issues/21960 -- a conflict on the assembly NewtonSoft.Json due to modules loading 2 different versions and Windows PowerShell (aka 5.1 and older) do not know what to do when there are multiple versions of the same assembly loaded, causing this error.
I posted a work-around and script to implement it in that same thread here: https://github.com/Azure/azure-powershell/issues/21960#issuecomment-2225896241
I have been leveraging this solution in 2 production automation platforms that use PowerShell in sandboxed processes (1 being AzureAutomation w/ HybridWorkers) without issue for nearly 6 months now.
The only quirk is some modules have to be imported in a specific order to be happy if more than 1 is used in your script: 1) Az.* 2) Graph.* 3) ExchangeOnline
I have only had to re-apply the bindingRedirect once when the app was updated and it was overwritten
Someone should take care of this now, as the upcoming breaking change in AZ.Accounts will force everyone to upgrade to AZ.Accounts > 2.12.1 Dont know why nobody @microsoft takes care of this problem in VSCode, this is open since over a year now! Exactly as mentioned by @ITJoeSchmo in the comment above in Case https://github.com/Azure/azure-powershell/issues/21960 PLEASE try to fix that in VSCode with PS5.1
Commenting to keep this alive.
Still an issue 9 months later.
I called Microsoft for issues in Modules related to automation accounts in azure, no one is bothered. I have downgraded Graph modules and now code is broken with az module. Scripts working like anything in a windows server. Azure automation is not a good choice.