Skip to content

Az.Resources 10.x.x is incompatible with Windows Powershell 5.1 #30201

Closed

Description

@zeilemaker54

Description

When removing a shared dashboard resource with the Remove-AzResource cmdlet using Az.Resource module version 10.x.x. with Windows Powershell 5.1 an exception is thrown: Remove-AzResource : The type initializer for 'ApiVersionCache' threw an exception.

Issue script & Debug output

Remove-AzResource -ResourceGroupName 'obtestazuresql-o-we-rg' -ResourceName 'obtestazuresql-o-we-dash' -ResourceType 'Microsoft.Portal/dashboards' -Force -Verbose
DEBUG: 11:28:25 AM - [ConfigManager] Got nothing from [DisplaySecretsWarning], Module = [], Cmdlet = []. Returning
default value [True].
DEBUG: 11:28:25 AM - RemoveAzureResourceCmdlet begin processing with ParameterSet 'BySubscriptionLevel'.
DEBUG: 11:28:25 AM - using account id 'xxxx'...
DEBUG: 11:28:25 AM - [ConfigManager] Got [True] from [DisplayBreakingChangeWarning], Module = [Az.Resources], Cmdlet =
[Remove-AzResource].
VERBOSE: Performing the operation "Deleting the resource..." on target
"/subscriptions/248b9b32-4c8c-49ad-8fd0-53cbad73d015/resourceGroups/obtestazuresql-o-we-rg/providers/Microsoft.Portal/d
ashboards/obtestazuresql-o-we-dash".
DEBUG: 11:28:25 AM - [ConfigManager] Got nothing from [EnableErrorRecordsPersistence], Module = [Az.Resources], Cmdlet
= [Remove-AzResource]. Returning default value [False].
Remove-AzResource : The type initializer for 'ApiVersionCache' threw an exception.
At line:1 char:1
+ Remove-AzResource -ResourceGroupName 'obtestazuresql-o-we-rg' -Resour ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Remove-AzResource], TypeInitializationException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.RemoveAzureResourceCmdle
   t

DEBUG: 11:28:25 AM - [ConfigManager] Got [True] from [DisplayBreakingChangeWarning], Module = [Az.Resources], Cmdlet =
[Remove-AzResource].
DEBUG: 11:28:25 AM - [ConfigManager] Got [False] from [DisplayRegionIdentified], Module = [], Cmdlet = [].
DEBUG: 11:28:25 AM - [ConfigManager] Got nothing from [CheckForUpgrade], Module = [], Cmdlet = []. Returning default
value [True].
DEBUG: 11:28:25 AM - No authentication telemetry is found for the current cmdlet with Id
b4e64dc8-3e89-40fb-b7d5-fd43d1c675f0.
DEBUG: AzureQoSEvent:  Module: Az.Resources:10.2.1; CommandName: Remove-AzResource; PSVersion: 5.1.26100.9444;
IsSuccess: False; Duration: 00:00:00.0244848; SanitizeDuration: 00:00:00; Exception: The type initializer for
'ApiVersionCache' threw an exception.;
DEBUG: 11:28:25 AM - [ConfigManager] Got [False] from [EnableDataCollection], Module = [], Cmdlet = [].
DEBUG: 11:28:25 AM - RemoveAzureResourceCmdlet end processing.

Environment data

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

Module versions

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     5.5.3      Az.Accounts                         {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear...
Script     10.2.1     Az.Resources                        {Export-AzResourceGroup, Export-AzTemplateSpec, Get-AzDeny...

Error output

DEBUG: 11:33:12 AM - [ConfigManager] Got nothing from [DisplaySecretsWarning], Module = [], Cmdlet = []. Returning
default value [True].
DEBUG: 11:33:12 AM - ResolveError begin processing with ParameterSet 'AnyErrorParameterSet'.
DEBUG: 11:33:12 AM - using account id 'xxx'...
DEBUG: 11:33:12 AM - [ConfigManager] Got [True] from [DisplayBreakingChangeWarning], Module = [Az.Accounts], Cmdlet =
[Resolve-AzError].
DEBUG: 11:33:12 AM - [ConfigManager] Got nothing from [DisplaySecretsWarning], Module = [], Cmdlet = []. Returning
default value [True].


   HistoryId: 8


Message        : The type initializer for 'ApiVersionCache' threw an exception.
StackTrace     :    at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components.ApiVersionHelper.ApiVersionCache.Get
                 CacheKey(String environmentName, String providerNamespace, String resourceType)
                    at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components.ApiVersionHelper.DetermineApiVersion
                 (IAzureContext context, String providerNamespace, String resourceType, Boolean pre)
                    at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.ResourceManagerCmdletBaseWithApi
                 Version.DetermineApiVersion(String resourceId)
                    at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.RemoveAzureResourceCmdlet.<>c__D
                 isplayClass4_0.<OnProcessRecord>b__0()
                    at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ConfirmAction(Boolean force,
                 String continueMessage, String processMessage, String target, Action action, Func`1 useShouldContinue)
                    at Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet.ConfirmAction(Boolean force,
                 String continueMessage, String processMessage, String target, Action action)
                    at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.RemoveAzureResourceCmdlet.OnProc
                 essRecord()
                    at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.ResourceManagerCmdletBase.Execut
                 eCmdlet()
                    at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
Exception      : System.TypeInitializationException
InvocationInfo : {Remove-AzResource}
Line           : Remove-AzResource -ResourceGroupName 'obtestazuresql-o-we-rg' -ResourceName
                 'obtestazuresql-o-we-dash' -ResourceType 'Microsoft.Portal/dashboards' -Force
Position       : At line:1 char:1
                 + Remove-AzResource -ResourceGroupName 'obtestazuresql-o-we-rg' -Resour ...
                 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 8

DEBUG: 11:33:13 AM - [ConfigManager] Got nothing from [DisplaySecretsWarning], Module = [], Cmdlet = []. Returning
default value [True].
Message        : Could not load file or assembly 'Microsoft.Extensions.Options, Version=2.2.0.0, Culture=neutral,
                 PublicKeyToken=adb9793829ddae60' or one of its dependencies. The system cannot find the file
                 specified.
StackTrace     :    at
                 Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components.ApiVersionHelper.ApiVersionCache..cctor()
Exception      : System.IO.FileNotFoundException
InvocationInfo : {Remove-AzResource}
Line           : Remove-AzResource -ResourceGroupName 'obtestazuresql-o-we-rg' -ResourceName
                 'obtestazuresql-o-we-dash' -ResourceType 'Microsoft.Portal/dashboards' -Force
Position       : At line:1 char:1
                 + Remove-AzResource -ResourceGroupName 'obtestazuresql-o-we-rg' -Resour ...
                 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 8



DEBUG: 11:33:13 AM - [ConfigManager] Got [False] from [DisplayRegionIdentified], Module = [], Cmdlet = [].
DEBUG: 11:33:13 AM - [ConfigManager] Got nothing from [CheckForUpgrade], Module = [], Cmdlet = []. Returning default
value [True].
DEBUG: 11:33:13 AM - No authentication telemetry is found for the current cmdlet with Id
3ee552e0-78af-431f-8358-6009176df32c.
DEBUG: AzureQoSEvent:  Module: Az.Accounts:5.5.3; CommandName: Resolve-AzError; PSVersion: 5.1.26100.9444; IsSuccess:
True; Duration: 00:00:00.1606525; SanitizeDuration: 00:00:00.0009148
DEBUG: 11:33:13 AM - [ConfigManager] Got [False] from [EnableDataCollection], Module = [], Cmdlet = [].
DEBUG: 11:33:13 AM - ResolveError end processing.

Activity

  1. added
    bugThis issue requires a change to an existing behavior in the product in order to be resolved.
    needs-triageThis is a new issue that needs to be triaged to the appropriate team.
    on Sep 25, 2026
  2. microsoft-github-policy-service commented on Sep 25, 2026

    @microsoft-github-policy-service
    Contributor

    🔔 Routing this issue to @Azure/act-identity-squad.

  3. x-engineering-agent commented on Sep 25, 2026

    @x-engineering-agent

    Bug Analysis

    Affected module: Az.Resources (src/Resources/), not ResourceGraph. Target branch: main.

    Use this exact PR title: [Resources] Fix Remove-AzResource API-version cache loading on Windows PowerShell 5.1

    Evidence and expected behavior

    The report is sufficiently specified: Windows PowerShell 5.1.26100.9444, Desktop edition, CLR 4.0.30319.42000, Az.Resources 10.2.1, and Az.Accounts 5.5.3. The failing command is below; resource names have been replaced with variables:

    Remove-AzResource -ResourceGroupName $resourceGroupName -ResourceName $dashboardName -ResourceType 'Microsoft.Portal/dashboards' -Force -Verbose

    With no explicit -ApiVersion, deleting an existing dashboard should resolve a supported API version and perform the deletion. Instead, ApiVersionCache throws TypeInitializationException; the supplied inner exception is FileNotFoundException for Microsoft.Extensions.Options, Version=2.2.0.0 or one of its dependencies. This is a client-side assembly-loading failure before the delete request, not evidence of a dashboard service failure. The concrete reported version is 10.2.1; this analysis does not establish that every 10.x version fails.

    Source-based diagnosis

    Source was inspected at fbd0af1011c9cb8d15b66b59f24ede820c501ee7:

    • RemoveAzureResourceCmdlet.OnProcessRecord calls DetermineApiVersion before DeleteResource. The base implementation bypasses discovery only when -ApiVersion is supplied.
    • ApiVersionHelper.DetermineApiVersion accesses the cache. Its static initializer constructs MemoryCache(new MemoryCacheOptions()), matching the reported failing initializer. ResourceManager.csproj references Microsoft.Extensions.Caching.Memory 2.2.0.
    • The module manifest advertises Desktop/PowerShell 5.1 support and already lists Microsoft.Extensions.Options.dll among required assemblies. Merely adding that manifest entry is not a fix. The unresolved point is whether the shipped dependency closure lacks the required assembly identity/dependency, or assembly binding/import order selects an incompatible version; source inspection alone cannot distinguish these.

    Focused correction

    Inspect the resolved and shipped caching/Options dependency identities and the existing module-loading behavior on Windows PowerShell 5.1. Correct the module-scoped dependency/reference or loading mismatch so the cache's complete compatible dependency closure resolves in a clean supported host, including with Az.Accounts loaded. Start in the handwritten ResourceManager implementation/project and Resources packaging inputs; do not change unrelated services, hardcode a dashboard API version, suppress the initialization failure, or require users to change process-wide binding configuration. Preserve the cache's environment/provider/resource-type key, one-hour expiration, and existing default/stable/preview API-version selection behavior.

    This path is handwritten, not an AutoRest-generated cmdlet. Avoid generated-file edits; if a durable AutoRest input does become necessary, follow the conditional generation protocol below.

    Regression coverage for the queued fix

    • Add a clean-process Windows PowerShell 5.1 regression using the packaged module/dependencies that exercises the real cache initializer and automatic API-version discovery, with Az.Accounts 5.5.3 present. A development test runner with already-loaded assemblies is insufficient; retain supported PowerShell 7 coverage too.
    • Cover the reported dashboard resource type with provider/delete calls mocked or recorded through the existing framework. Exercise omitted -ApiVersion, explicit -ApiVersion as a control, and a repeated cached lookup; retain current selection/fallback coverage. Do not hardcode subscription IDs, resource names, or locations, and keep scenario tests re-recordable.
    • ResourceTypeApiVersionTests currently invokes the selection helpers by reflection, bypassing the cache initializer. Extend coverage beyond those helpers; existing removal scenarios are in ResourceTests.cs.

    This is a triage handoff for durable queuing only; no implementation or tests were run during this triage.

    Mandatory Codegen execution protocol

    Before editing implementation files, inspect src/Resources/ and determine whether the affected cmdlet belongs to a *.Autorest project. Classify the change before editing: REST schema and operation defects belong in the pinned Azure/azure-rest-api-specs input; PowerShell-specific public surface shaping belongs in the project README.md directives; non-modelable client behavior belongs in handwritten custom/; examples and tests remain handwritten. Do not directly synthesize or patch generated C#, proxy scripts, docs/, manifests, models, or the committed top-level generated/ tree.

    Use the Azure PowerShell repository's Codegen MCP documentation. Invoke its generate-autorest tool with the absolute *.Autorest working directory when that MCP tool is available. Otherwise execute the same repository-owned non-interactive sequence documented by the tool implementation:

    cd <absolute-path-to-Project.Autorest>
    autorest --reset
    autorest
    pwsh -File build-module.ps1

    You MUST actually run Codegen after changing its durable inputs; do not merely describe these commands in the pull request. If the required tools cannot be installed or any generation step fails, stop and report the blocker instead of hand-authoring a substitute. Commit the complete generated diff, including a Codegen-created change to generate-info.json (the exact filename; never fabricate its generate_Id), then inspect the diff and run the focused module build, help, StaticAnalysis, and tests. A change confined to handwritten custom/, examples/, or completed tests does not become generated merely because it is inside a *.Autorest project.

    PR title & description (azure-powershell)

    Follow CONTRIBUTING.md. azure-powershell does not enforce a strict title gate — it requires a clear, informative title and a fully filled-out PR template.

    Suggested PR title (clear & informative; [Module] prefix is the common convention):

    [Resources] Fix Remove-AzResource API-version cache loading on Windows PowerShell 5.1
    

    Required (per CONTRIBUTING.md):

    • Fill out the PR template completely — PRs are not reviewed without the completed checklist; do not delete it.
    • Link the issue — include Fixes #30201 in the description so the PR auto-closes it.
    • ChangeLog — add a bullet describing the fix under the ## Upcoming Release header of src/Resources/Resources/ChangeLog.md. Do not add a new version header.
    • Target branch — main.
    • Tests — add/adjust test coverage for the change. Tests must not contain hardcoded values (location, resource id, etc.) and must be re-recordable; do not skip existing tests.
    • AutoRest/Codegen — if the change touches a *.Autorest project, run the repository's approved Codegen flow and include all regenerated artifacts, including that project's changed generate-info.json. Do not submit only hand-edited AutoRest source or generated output.
    • Scope — keep the change limited to the affected module (src/Resources/).
  4. isra-fel commented on Sep 30, 2026

    @isra-fel
    Member

    The assembly that has trouble loading is Microsoft.Extensions.Options. It was added in #29654 as an intermideate dependency of Azure.Identity library.

    It seems it's also a dependency inside Az.Resources and caused the issue.

    Will try to reproduce first.

    Possible fixes:

    1. add it to the CrossMajorVersionRedirectionAllowList
    2. figure out how it is referenced in Az.Resources and try to update to the same version or remove the dependency

    Update: can reproduce with latest Az.Accounts and Az.Resources.

    5.5.3 az.accounts

    10.2.1 az.resources

    Detailed log
    PS C:\Users\[s]> $error[0].exception | fl * -f
    
    
    TypeName       : ApiVersionCache
    Message        : The type initializer for 'ApiVersionCache' threw an exception.
    Data           : {}
    InnerException : System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Extensions.Options,
                     Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The
                     system cannot find the file specified.
                     File name: 'Microsoft.Extensions.Options, Version=2.2.0.0, Culture=neutral,
                     PublicKeyToken=adb9793829ddae60'
                        at
                     Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components.ApiVersionHelper.ApiVersionCache..cctor()
    
                     Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
                     Running under executable  C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
                     --- A detailed error log follows.
    
                     === Pre-bind state information ===
                     LOG: DisplayName = Microsoft.Extensions.Options, Version=2.2.0.0, Culture=neutral,
                     PublicKeyToken=adb9793829ddae60
                      (Fully-specified)
                     LOG: Appbase = file:///C:/Windows/System32/WindowsPowerShell/v1.0/
                     LOG: Initial PrivatePath = NULL
                     Calling assembly : Microsoft.Extensions.Caching.Memory, Version=2.2.0.0, Culture=neutral,
                     PublicKeyToken=adb9793829ddae60.
                     ===
                     LOG: This bind starts in LoadFrom load context.
                     WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default
                     load context, like with Assembly.Load().
                     LOG: Using application configuration file:
                     C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe.Config
                     LOG: Using host configuration file:
                     LOG: Using machine configuration file from
                     C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
                     LOG: Post-policy reference: Microsoft.Extensions.Options, Version=2.2.0.0, Culture=neutral,
                     PublicKeyToken=adb9793829ddae60
                     LOG: Attempting download of new URL
                     file:///C:/Windows/System32/WindowsPowerShell/v1.0/Microsoft.Extensions.Options.DLL.
                     LOG: Attempting download of new URL file:///C:/Windows/System32/WindowsPowerShell/v1.0/Microsoft.Exten
                     sions.Options/Microsoft.Extensions.Options.DLL.
                     LOG: Attempting download of new URL
                     file:///C:/Windows/System32/WindowsPowerShell/v1.0/Microsoft.Extensions.Options.EXE.
                     LOG: Attempting download of new URL file:///C:/Windows/System32/WindowsPowerShell/v1.0/Microsoft.Exten
                     sions.Options/Microsoft.Extensions.Options.EXE.
                     LOG: Attempting download of new URL file:///C:/Users//Documents/WindowsPowerShell/Modules/az.reso
                     urces/10.2.1/Microsoft.Extensions.Options.DLL.
                     WRN: Comparing the assembly name resulted in the mismatch: Major Version
                     LOG: Attempting download of new URL file:///C:/Users//Documents/WindowsPowerShell/Modules/az.reso
                     urces/10.2.1/Microsoft.Extensions.Options/Microsoft.Extensions.Options.DLL.
                     LOG: Attempting download of new URL file:///C:/Users//Documents/WindowsPowerShell/Modules/az.reso
                     urces/10.2.1/Microsoft.Extensions.Options.EXE.
                     LOG: Attempting download of new URL file:///C:/Users//Documents/WindowsPowerShell/Modules/az.reso
                     urces/10.2.1/Microsoft.Extensions.Options/Microsoft.Extensions.Options.EXE.
    
    TargetSite     : System.String GetCacheKey(System.String, System.String, System.String)
    StackTrace     :    at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components.ApiVersionHelper.ApiVersionCache.Get
                     CacheKey(String environmentName, String providerNamespace, String resourceType)
                        at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components.ApiVersionHelper.DetermineApiVersion
                     (IAzureContext context, String providerNamespace, String resourceType, Boolean pre)
                        at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.ResourceManagerCmdletBaseWithApi
                     Version.DetermineApiVersion(String resourceId)
                        at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.RemoveAzureResourceCmdlet.<>c__D
                     isplayClass4_0.<OnProcessRecord>b__0()
                        at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ConfirmAction(Boolean force,
                     String continueMessage, String processMessage, String target, Action action, Func`1 useShouldContinue)
                        at Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet.ConfirmAction(Boolean force,
                     String continueMessage, String processMessage, String target, Action action)
                        at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.RemoveAzureResourceCmdlet.OnProc
                     essRecord()
                        at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.ResourceManagerCmdletBase.Execut
                     eCmdlet()
                        at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
    HelpLink       :
    Source         : Microsoft.Azure.PowerShell.Cmdlets.ResourceManager
    HResult        : -2146233036
    
    ......
    FullName            : Microsoft.Extensions.Options, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
    Location            : C:\Users\yeliu\Documents\WindowsPowerShell\Modules\az.accounts\5.5.3\lib\netstandard2.0\Microsoft.Extensions.Options.dll
    AssemblyFileVersion : 10.0.326.7603
    TargetFramework     : .NETStandard,Version=v2.0
    
  5. microsoft-github-policy-service commented on Oct 2, 2026

    @microsoft-github-policy-service
    Contributor

    🔔 Routing this issue to @Azure/act-identity-squad.

  6. microsoft-github-policy-service commented on Oct 2, 2026

    @microsoft-github-policy-service
    Contributor

    🔔 Routing this issue to @Azure/act-identity-squad.

  7. x-engineering-agent commented on Oct 2, 2026

    @x-engineering-agent

    Implementation Result

    No pull request was opened because the implementation run completed without a validated code change.

    The source analysis remains available above. A maintainer should confirm whether the issue is already resolved on the current target branch or provide the reproduction or root-cause evidence needed for another implementation request.

    Posted by x-engineering-agent (Fixer)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ARMact-identity-squadbugThis issue requires a change to an existing behavior in the product in order to be resolved.customer-reported

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions