Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect-AzAccount : Method 'get_SerializationSettings' in type #22903

Open
MaMouette opened this issue Oct 5, 2023 · 8 comments
Open

Connect-AzAccount : Method 'get_SerializationSettings' in type #22903

MaMouette opened this issue Oct 5, 2023 · 8 comments
Labels
customer-reported needs-team-attention This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that

Comments

@MaMouette
Copy link

Description

Hello,
I'm on a windows 2026 server.
I installed the az.storage 5.10.0 module (which installs the az.accounts module 2.13.1).
The command "connect-azaccount" fails with the error "Method 'get_SerializationSettings' in type..".
Articles say that I should use the older version of az.accounts 2.12.1. I uninstalled the 2.13.1? install the 2.12.1. It's OK :-).
But later in my script I need the command "get-AZStorageaccount..". It's not OK:
import-module az.storage gives the error
"C:\Program Files\WindowsPowerShell\Modules\Az.Storage\5.10.1\Az.Storage.psm1 : This module requires Az.Accounts
version 2.13.1. An earlier version of Az.Accounts is imported in the current PowerShell session"

OK, I tried to
remove-module az.accounts -Force
Install-Module -Name Az.Accounts # it's ok, installing the 2.13.1 module sid by side with 2.12.1
import-module az.storage
-->
Import-Module : Could not load type
'Microsoft.WindowsAzure.Commands.Common.CustomAttributes.GenericBreakingChangeWithVersionAttribute' from assembly
'Microsoft.Azure.PowerShell.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
At C:\Program Files\WindowsPowerShell\Modules\az.storage\5.10.1\Az.Storage.psm1:99 char:1

  • Import-Module (Join-Path -Path $PSScriptRoot -ChildPath Microsoft.Azu ...
  •   + CategoryInfo          : NotSpecified: (:) [Import-Module], TypeLoadException
      + FullyQualifiedErrorId : System.TypeLoadException,Microsoft.PowerShell.Commands.ImportModuleCommand
    
    

On an other wn2016 server, with the same .Net framework version installed (the highest possible one is 4.8 on this OS), and the same powershell modules az.storage 5.10.0 module (which installs the az.accounts module 2.13.1), all my commands are OK.

I do not understand.
Any other idea ?
Thank you.

Script or Debug output

No response

Environment data

Name                           Value
----                           -----
PSVersion                      5.1.14393.5582
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.5582
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Module versions

Script     2.13.1     Az.Accounts
Script     5.10.1     Az.Storage

Error output

Message        : Could not load type
                 'Microsoft.WindowsAzure.Commands.Common.CustomAttributes.GenericBreakingChangeWithVersionAttribute'
                 from assembly 'Microsoft.Azure.PowerShell.Common, Version=1.0.0.0, Culture=neutral,
                 PublicKeyToken=31bf3856ad364e35'.
StackTrace     :    at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs,
                 Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
                    at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken,
                 RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
                    at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments,
                 Type[] genericMethodArguments)
                    at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord,
                 MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken
                 decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes,
                 IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean&
                 ctorHasParameters, Boolean& isVarArg)
                    at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32
                 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable,
                 IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)
                    at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType,
                 Boolean inherit)
                    at System.Attribute.GetCustomAttributes(MemberInfo element, Type type, Boolean inherit)
                    at System.Reflection.CustomAttributeExtensions.GetCustomAttributes[T](MemberInfo element, Boolean
                 inherit)
                    at System.Management.Automation.Runspaces.PSSnapInHelpers.GetCustomAttribute[T](TypeInfo
                 decoratedType)
                    at
                 System.Management.Automation.Runspaces.PSSnapInHelpers.AnalyzeModuleAssemblyWithReflection(Assembly
                 assembly, String name, PSSnapInInfo psSnapInInfo, PSModuleInfo moduleInfo, Boolean isModuleLoad,
                 Dictionary`2& cmdlets, Dictionary`2& aliases, Dictionary`2& providers, String helpFile, Type&
                 randomCmdletToCheckLinkDemand, Type& randomProviderToCheckLinkDemand)
                    at System.Management.Automation.Runspaces.PSSnapInHelpers.AnalyzePSSnapInAssembly(Assembly
                 assembly, String name, PSSnapInInfo psSnapInInfo, PSModuleInfo moduleInfo, Boolean isModuleLoad,
                 Dictionary`2& cmdlets, Dictionary`2& aliases, Dictionary`2& providers, String& helpFile)
                    at System.Management.Automation.Runspaces.InitialSessionState.ImportCmdletsFromAssembly(Assembly
                 assembly, PSModuleInfo module)
                    at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadBinaryModule(PSModuleInfo parentModule,
                 Boolean trySnapInName, String moduleName, String fileName, Assembly assemblyToLoad, String
                 moduleBase, SessionState ss, ImportModuleOptions options, ManifestProcessingFlags
                 manifestProcessingFlags, String prefix, Boolean loadTypes, Boolean loadFormats, Boolean& found,
                 String shortModuleName, Boolean disableFormatUpdates)
                    at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModule(PSModuleInfo parentModule, String
                 fileName, String moduleBase, String prefix, SessionState ss, Object privateData, ImportModuleOptions&
                 options, ManifestProcessingFlags manifestProcessingFlags, Boolean& found, Boolean& moduleFileFound)
                    at
                 Microsoft.PowerShell.Commands.ImportModuleCommand.ImportModule_LocallyViaName(ImportModuleOptions
                 importModuleOptions, String name)
                    at Microsoft.PowerShell.Commands.ImportModuleCommand.ProcessRecord()
                    at System.Management.Automation.CommandProcessor.ProcessRecord()
Exception      : System.TypeLoadException
InvocationInfo : {Import-Module}
Line           : Import-Module (Join-Path -Path $PSScriptRoot -ChildPath
                 Microsoft.Azure.PowerShell.Cmdlets.Storage.dll)
@MaMouette MaMouette added needs-triage This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Oct 5, 2023
@microsoft-github-policy-service microsoft-github-policy-service bot added customer-reported and removed needs-triage This is a new issue that needs to be triaged to the appropriate team. labels Oct 5, 2023
@isra-fel
Copy link
Member

isra-fel commented Oct 8, 2023

Thanks for reporting! I cannot reproduce this issue.
Please remove all the Az modules and try again. When you remove them, double check by Get-Module Az* -ListAvailable. It should give no response. Also, make sure to close any open powershell session when removing.

@isra-fel isra-fel added the needs-author-feedback More information is needed from author to address the issue. label Oct 8, 2023
@MaMouette
Copy link
Author

Yes, I did it. Get-Module Az* -ListAvailable: empty. Reinstall modules. Same issue.
Thank you.

@microsoft-github-policy-service microsoft-github-policy-service bot added needs-team-attention This issue needs attention from Azure service team or SDK team and removed needs-author-feedback More information is needed from author to address the issue. labels Oct 9, 2023
@isra-fel
Copy link
Member

isra-fel commented Nov 2, 2023

Could you run the function defined here to get a list of Newtonsoft.Json dlls imported in the PS session? https://gist.github.com/isra-fel/f3b94f56775df8ba56aa3c0444f484c6

You need to copy-paste the definition of the function then run it like this: asm json.
The result may help us locate the older version of Newtonsoft.JSON.

@isra-fel isra-fel added needs-author-feedback More information is needed from author to address the issue. and removed needs-team-attention This issue needs attention from Azure service team or SDK team labels Nov 2, 2023
@MaMouette
Copy link
Author

MaMouette commented Nov 2, 2023 via email

@microsoft-github-policy-service microsoft-github-policy-service bot added needs-team-attention This issue needs attention from Azure service team or SDK team and removed needs-author-feedback More information is needed from author to address the issue. labels Nov 2, 2023
@GDMTT
Copy link

GDMTT commented Nov 7, 2023

I'm having the same issue when using PowerShell from VS Code.

`
Connect-AzAccount -Tenant "zzzzzzzzzzzzzzzzzzzzzzzzzzzz" -sub "zzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
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 -Tenant "2156b869-431f-4815-b2ce-b4893b5c9aaa" -sub ...
  •   + CategoryInfo          : NotSpecified: (:) [Connect-AzAccount], TypeLoadException
      + FullyQualifiedErrorId : System.TypeLoadException,Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand
    

`
but when I run it from ISE PowerShell it works as expected.

I ran the am function in VSC PowerShell and I get :

`
FullName : Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
Location : C:\Users\GregoryM.vscode\extensions\ms-vscode.powershell-2023.8.0\modules\PSScriptAnalyzer\1.21.0\Newtonsoft.Json.dll

FullName : Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
Location : C:\Users\GregoryM.vscode\extensions\ms-vscode.powershell-2023.8.0\modules\PowerShellEditorServices\bin\Common\Newtonsoft.Json.dll

FullName : OmniSharp.Extensions.JsonRpc, Version=0.19.0.0, Culture=neutral, PublicKeyToken=6d868dff454e6022
Location : C:\Users\GregoryM.vscode\extensions\ms-vscode.powershell-2023.8.0\modules\PowerShellEditorServices\bin\Common\OmniSharp.Extensions.JsonRpc.dll

FullName : System.Text.Json, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
Location : C:\Users\GregoryM\OneDrive - Name \Documents\WindowsPowerShell\Modules\Az.Accounts\2.13.1\lib\netstandard2.0\System.Text.Json.dll
`

when I run it in ISE PowerShell I get
`
FullName : Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
Location : C:\Users\GregoryM\OneDrive - Name \Documents\WindowsPowerShell\Modules\Az.Accounts\2.13.1\lib\netfx\Newtonsoft.Json.dll

FullName : System.Text.Json, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
Location : C:\Users\GregoryM\OneDrive - Name \Documents\WindowsPowerShell\Modules\Az.Accounts\2.13.1\lib\netstandard2.0\System.Text.Json.dl
`
so it looks like there are different libraries being used.

Any suggests to resolve this ?

@sevacloud
Copy link

sevacloud commented Nov 29, 2023

Also affected by this, VSCode not working with the same error but Powershell ISE ok

PS C:\Users\User\Documents\Web Development\git> Add-AzAccount -Credential $Credential
Add-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
+ Add-AzAccount -Credential $Credential
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Connect-AzAccount], TypeLoadException
    + FullyQualifiedErrorId : System.TypeLoadException,Microsoft.Azure.Commands.Profile.ConnectAzureRmAccount  
   Command

VSCode

FullName : Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
Location : C:\Users\User\.vscode\extensions\ms-vscode.powershell-2023.8.0\modules\PSScriptAnalyzer\1.21.0\New 
           tonsoft.Json.dll

FullName : Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
Location : C:\Users\User\.vscode\extensions\ms-vscode.powershell-2023.8.0\modules\PowerShellEditorServices\bi 
           n\Common\Newtonsoft.Json.dll

FullName : OmniSharp.Extensions.JsonRpc, Version=0.19.0.0, Culture=neutral, PublicKeyToken=6d868dff454e6022    
Location : C:\Users\User\.vscode\extensions\ms-vscode.powershell-2023.8.0\modules\PowerShellEditorServices\bi 
           n\Common\OmniSharp.Extensions.JsonRpc.dll

FullName : System.Text.Json, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
Location : C:\Program
           Files\WindowsPowerShell\Modules\Az.Accounts\2.13.2\lib\netstandard2.0\System.Text.Json.dll

Powershell

FullName : Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
Location : C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.13.2\lib\netfx\Newtonsoft.Json.dll

FullName : System.Text.Json, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
Location : C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\2.13.2\lib\netstandard2.0\System.Text.Json.dll

Module Imports

Import-Module -Name 'Az.Accounts' -RequiredVersion '2.13.2'
Import-Module -Name 'Az.Storage' -RequiredVersion '6.0.0'

@mwasham
Copy link

mwasham commented Jun 26, 2024

Are there any plans to ever fix this or is PowerShell not a supported tool for Azure anymore?

@ITJoeSchmo
Copy link

ITJoeSchmo commented Jul 12, 2024

Same issue as here: #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: #21960 (comment)

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer-reported needs-team-attention This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
None yet
Development

No branches or pull requests

6 participants