Skip to content

Az.Accounts 5.5.1 bumps Microsoft.Extensions.Options to 10.0.0.0, breaking PnP.PowerShell in the PS 7.4 Functions worker (MissingMethodException) #29833

Description

@andystaples

Summary

Az.Accounts 5.5.1 ships a newer Microsoft.Extensions.Options (assembly version 10.0.0.0) than 5.5.0 (which shipped 8.0.0.0). In the Azure Functions PowerShell 7.4 worker, this newer assembly gets co-loaded with modules that bundle Microsoft.Extensions.Http 8.0.0.0 (e.g. PnP.PowerShell 3.2.0 / PnP.Framework), and the resulting binding mismatch throws a System.MissingMethodException.

Downgrading to Az.Accounts 5.5.0 resolves it. Reported by multiple customers.

Companion worker-side issue: Azure/azure-functions-powershell-worker#1144 (full worker analysis, repro, and worker-isolation question).

Exception

System.MissingMethodException: Method not found:
  'Microsoft.Extensions.DependencyInjection.IServiceCollection
   Microsoft.Extensions.DependencyInjection.OptionsServiceCollectionExtensions.AddOptions(
     Microsoft.Extensions.DependencyInjection.IServiceCollection)'.
  at Microsoft.Extensions.DependencyInjection.HttpClientFactoryServiceCollectionExtensions.AddHttpClient(IServiceCollection services)
  at PnP.Framework.Http.PnPHttpClient.AddHttpClients(IServiceCollection collection, String UserAgent)
  ...
  at PnP.PowerShell.Commands.Base.ConnectOnline.ProcessRecord()

What changed between 5.5.0 and 5.5.1

Controlled test — only the Az.Accounts version changed, same worker (PS 7.4.13 / .NET 8), same PnP.PowerShell 3.2.0:

Az.Accounts Microsoft.Extensions.Options loaded Result
5.5.1 10.0.0.0 MissingMethodException
5.5.0 8.0.0.0 ✅ works

Microsoft.Extensions.Http 8.0.0.0 (from PnP.Framework) calls the AddOptions(IServiceCollection) overload that Microsoft.Extensions.Options 10.0.0.0 no longer exposes.

Reproduction

requirements.psd1 in a PowerShell 7.4 Functions app:

@{
    'Az.Accounts'    = '5.5.1'
    'Az.Resources'   = '10.0.0'
    'Az.Storage'     = '9.7.0'
    'PnP.PowerShell'  = '3.2.0'
    'Az.KeyVault'    = '6.5.0'
}
Import-Module Az.Accounts
Import-Module PnP.PowerShell
Connect-PnPOnline -Url 'https://contoso.sharepoint.com' -ClientId '<id>' -ClientSecret '<secret>'
# -> System.MissingMethodException

Note: reproduced only inside the Functions worker; a bare pwsh 7.4.13 with the same modules does not crash (see #1144). But since the trigger is the Microsoft.Extensions.Options version bump in 5.5.1, raising here as well.

Workaround

'Az.Accounts' = '5.5.0'

Ask

  • Was the Microsoft.Extensions.Options bump to 10.0.0.0 in Az.Accounts 5.5.1 intentional, and is it expected to coexist with modules bundling Microsoft.Extensions.Http 8.0.0.0?
  • Any guidance for customers combining Az.Accounts 5.5.x with PnP.PowerShell in the PS 7.4 worker?

Environment

  • Az.Accounts 5.5.1
  • Azure Functions PowerShell worker 7.4.13 (.NET 8), Core Tools 4.12.1
  • Managed dependencies enabled

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions