azure-powershell icon indicating copy to clipboard operation
azure-powershell copied to clipboard

Method get_SerializationSettings exits command to try and login to Azure via Login-AzAccount -UseDeviceAuthentication with Azure Powershell

Open Ashoka1852 opened this issue 1 year ago • 3 comments

Description

I was able to reproduce the issue on both the Az as well as AzPreview:

Install-Module -Name Az -Scope CurrentUser
PS C:\Users\Madis\OneDrive\Desktop\Code_Snippits> Login-AzAccount -UseDeviceAuthentication Login-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

  • Login-AzAccount -UseDeviceAuthentication
  •   + CategoryInfo          : NotSpecified: (:) [Connect-AzAccount], TypeLoadExcep 
     tion
      + FullyQualifiedErrorId : System.TypeLoadException,Microsoft.Azure.Commands.Pr 
     ofile.ConnectAzureRmAccountCommand
    
    
    

Issue script & Debug output

Login-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
+ Login-AzAccount -UseDeviceAuthentication
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Connect-AzAccount], TypeLoadExcep 
   tion
    + FullyQualifiedErrorId : System.TypeLoadException,Microsoft.Azure.Commands.Pr 
   ofile.ConnectAzureRmAccountCommand

Environment data

PSVersion                      5.1.22621.2506
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.22621.2506
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Module versions

USER PATH> Install-Module -Name Az -Scope CurrentUser
DEBUG: 00:00:00.0000003 Calling New() : MethodName = 'GetDynamicOptions'
DEBUG: 00:00:00.0000159 Name: Az
DEBUG: 00:00:00.0007495 INVOKING PowerShell Fn Get-DynamicOptions with args
Provider that has length 1
DEBUG: 00:00:00.0012596 In PowerShellGet Provider - 'Get-DynamicOptions'.
DEBUG: 00:00:00.0020529 Done calling powershell «Get-DynamicOptions» «PSModule»     
DEBUG: 00:00:00.0037531 Calling New() : MethodName = 'GetDynamicOptions'
DEBUG: 00:00:00.0037702 Name: Az
DEBUG: 00:00:00.0041703 INVOKING PowerShell Fn Get-DynamicOptions with args Source  
that has length 1
DEBUG: 00:00:00.0045825 In PowerShellGet Provider - 'Get-DynamicOptions'.
DEBUG: 00:00:00.0057733 Done calling powershell «Get-DynamicOptions» «PSModule»     
DEBUG: 00:00:00.0091678 Calling New() : MethodName = 'GetDynamicOptions'
DEBUG: 00:00:00.0091790 Name: Az
DEBUG: 00:00:00.0095105 INVOKING PowerShell Fn Get-DynamicOptions with args Package 
 that has length 1
DEBUG: 00:00:00.0098943 In PowerShellGet Provider - 'Get-DynamicOptions'.
DEBUG: 00:00:00.0118599 Done calling powershell «Get-DynamicOptions» «PSModule»     
DEBUG: 00:00:00.0139184 Calling New() : MethodName = 'GetDynamicOptions'
DEBUG: 00:00:00.0139300 Name: Az
DEBUG: 00:00:00.0142382 INVOKING PowerShell Fn Get-DynamicOptions with args Install 
 that has length 1
DEBUG: 00:00:00.0145955 In PowerShellGet Provider - 'Get-DynamicOptions'.
DEBUG: 00:00:00.0162874 Done calling powershell «Get-DynamicOptions» «PSModule»     
DEBUG: 00:00:00.0287501 Calling SearchForPackages. Name='Az'
DEBUG: 00:00:00.0294721 PackageProvider::FindPackage with name Az
DEBUG: 00:00:00.0296672 Calling SearchForPackages After Select 1
DEBUG: 00:00:00.0313770 Calling New() : MethodName = 'FindPackage'
DEBUG: 00:00:00.0320264 ProviderName: PowerShellGet
DEBUG: 00:00:00.0325862 Type: Module
DEBUG: 00:00:00.0331576 Scope: CurrentUser
DEBUG: 00:00:00.0338071 MessageResolver:
Microsoft.PowerShell.PackageManagement.Cmdlets.GetMessageString
DEBUG: 00:00:00.0343980 Name: Az
DEBUG: 00:00:00.0358170 INVOKING PowerShell Fn Find-Package with args
System.String[], , ,  that has length 4
DEBUG: 00:00:00.0371767 In PowerShellGet Provider - 'Find-Package'.
DEBUG: 00:00:00.0378309 OPTION: ProviderName => PowerShellGet
DEBUG: 00:00:00.0383879 OPTION: Type => Module
DEBUG: 00:00:00.0389992 OPTION: Scope => CurrentUser
DEBUG: 00:00:00.0395506 OPTION: MessageResolver =>
Microsoft.PowerShell.PackageManagement.Cmdlets.GetMessageString
DEBUG: 00:00:00.0402552 OPTION: Name => Az
DEBUG: 00:00:00.0473046 PackageProvider::FindPackage with name Az
DEBUG: 00:00:00.0506473 Calling 'NuGet'::'FindPackage' - name='Az',
requiredVersion='',minimumVersion='', maximumVersion='''.
DEBUG: 00:00:00.0515422 Iterating 'Az'.
DEBUG: 00:00:00.0529745 There are '0' registered sources in 'NuGet' provider.       
DEBUG: 00:00:00.0544141 Source 'https://www.powershellgallery.com/api/v2' is not    
one of the registered sources in 'NuGet' provider.
DEBUG: 00:00:01.2474395 Source 'https://www.powershellgallery.com/api/v2' is 
validated.
DEBUG: 00:00:01.2485227 Calling 'NuGetRequest'::'GetPackageById', 'Az'.
DEBUG: 00:00:01.4191395 Calling 'HttpClientPackageRepository'::'FindPackagesById', 
'Az'.
DEBUG: 00:00:01.4202422 Calling 'NuGetClient'::'FindPackage'.
DEBUG: 00:00:01.4213960 Downloading
'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='Az'&$skip=0&$top=4 
0'.
DEBUG: 00:00:01.6027893 Completed downloading 
'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='Az'&$skip=0&$top=4 
0'.
DEBUG: 00:00:01.6151468 Downloading
'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='Az'&$skip=160&$top 
=40'.
DEBUG: 00:00:01.6152162 Downloading
'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='Az'&$skip=120&$top 
=40'.
DEBUG: 00:00:01.6152922 Downloading
'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='Az'&$skip=40&$top= 
40'.
DEBUG: 00:00:01.6154080 Downloading
'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='Az'&$skip=80&$top= 
40'.
DEBUG: 00:00:01.7010218 Completed downloading 
'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='Az'&$skip=160&$top 
=40'.
DEBUG: 00:00:01.7023618 '0' packages received in the last request.
DEBUG: 00:00:01.7466881 Completed downloading 
'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='Az'&$skip=120&$top 
=40'.
DEBUG: 00:00:01.7476919 '0' packages received in the last request.
DEBUG: 00:00:01.7987825 Completed downloading 
'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='Az'&$skip=40&$top= 
40'.
DEBUG: 00:00:01.8661966 Completed downloading 
'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='Az'&$skip=80&$top= 
40'.
DEBUG: 00:00:01.8690997 '20' packages received in the last request.
DEBUG: 00:00:01.8767265 Completed iterating for 'Az'.
DEBUG: 00:00:01.9020498 Done calling powershell «Find-Package» «PSModule»
DEBUG: 00:00:01.9058771 Calling New() : MethodName = 'GetInstalledPackages'
DEBUG: 00:00:01.9068372 ProviderName: PowerShellGet
DEBUG: 00:00:01.9075182 Type: Module
DEBUG: 00:00:01.9080827 Scope: CurrentUser
DEBUG: 00:00:01.9085986 MessageResolver:
Microsoft.PowerShell.PackageManagement.Cmdlets.GetMessageString
DEBUG: 00:00:01.9091827 Name: Az
DEBUG: 00:00:01.9098194 INVOKING PowerShell Fn Get-InstalledPackage with args Az,   
11.2.0, ,  that has length 4
DEBUG: 00:00:01.9108762 In PowerShellGet Provider - 'Get-InstalledPackage'.
DEBUG: 00:00:01.9114643 OPTION: ProviderName => PowerShellGet
DEBUG: 00:00:01.9120129 OPTION: Type => Module
DEBUG: 00:00:01.9126564 OPTION: Scope => CurrentUser
DEBUG: 00:00:01.9133111 OPTION: MessageResolver =>
Microsoft.PowerShell.PackageManagement.Cmdlets.GetMessageString
DEBUG: 00:00:01.9139764 OPTION: Name => Az
DEBUG: 00:00:02.4972581 Done calling powershell «Get-InstalledPackage» «PSModule»
PS C:\Users\Madis\OneDrive\Desktop\Code_Snippits> Get-Module Az                     
PS C:\Users\Madis\OneDrive\Desktop\Code_Snippits> Get-Module -Az                    
Get-Module : A parameter cannot be found that matches parameter name 'Az'.
At line:1 char:12
+ Get-Module -Az
+            ~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-Module], ParameterBindingE  
   xception
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands  
   .GetModuleCommand

PS C:\Users\Madis\OneDrive\Desktop\Code_Snippits> Get-Module -Az*
Get-Module : A parameter cannot be found that matches parameter name 'Az*'.
At line:1 char:12
+ Get-Module -Az*
+            ~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-Module], ParameterBindingE  
   xception
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands  
   .GetModuleCommand

Error output

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], TypeLoadExcepti  
   on
    + FullyQualifiedErrorId : System.TypeLoadException,Microsoft.Azure.Commands.Pr  
   ofile.Errors.ResolveError

Ashoka1852 avatar Feb 05 '24 20:02 Ashoka1852

Please run [System.AppDomain]::CurrentDomain.GetAssemblies() | where {$_.FullName -ilike "*newtonsoft.json*" } | select -Property FullName,location | sort -Property FullName | fl and share the result. If you see Newtonsoft.Json being loaded from modules other than Az.Accounts, consider not using it together with Az.

Also, updating to PowerShell 7 could work-around this issue.

isra-fel avatar Feb 06 '24 09:02 isra-fel

Please run [System.AppDomain]::CurrentDomain.GetAssemblies() | where {$_.FullName -ilike "*newtonsoft.json*" } | select -Property FullName,location | sort -Property FullName | fl and share the result. If you see Newtonsoft.Json being loaded from modules other than Az.Accounts, consider not using it together with Az.

Also, updating to PowerShell 7 could work-around this issue.

If this is a newtonsoft.json assembly conflict from concurrently loading 2 versions, see my work around solution: https://github.com/Azure/azure-powershell/issues/21960#issuecomment-1938831513

ITJoeSchmo avatar Feb 13 '24 03:02 ITJoeSchmo

Solution: Enable-AzureRmAlias -Scope LocalMachine

The error was gone for me when I enabled AzureRmAlias which is officially the compatibility mode for migrating from AzureRM to AzurePowershell https://learn.microsoft.com/en-us/powershell/azure/migrate-from-azurerm-to-az?view=azps-11.3.0#option-2-use-compatibility-mode-with-enable-azurermalias. I restarted my application (in my case a windows service) and it worked.

Not sure if if this means that the newest AzurePowershell version has a dependency to AzureRM and needs this alias or why I need this enabled.

e-jr avatar Feb 15 '24 14:02 e-jr

Hi, we're sending this friendly reminder because we haven't heard back from you in a while. We need more information about this issue to help address it. Please be sure to give us your input within the next 7 days. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!

It looks like the newest AzurePowershell version has a dependency to AzureRM. Since enabling AzureRmAlias fixes the error. https://learn.microsoft.com/en-us/powershell/azure/migrate-from-azurerm-to-az?view=azps-11.3.0#option-2-use-compatibility-mode-with-enable-azurermalias This should be fixed because for normal use of AzurePowershell version it should not be neccessary to enable the compatibility mode.

e-jr avatar Feb 23 '24 07:02 e-jr

Hi, we're sending this friendly reminder because we haven't heard back from you in a while. We need more information about this issue to help address it. Please be sure to give us your input within the next 7 days. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!