Azure / Azure/azure-functions-powershell-worker

Advisory: Az.Accounts 5.5.1 + PnP.PowerShell crash the PS 7.4 worker with MissingMethodException (AddHttpClient/AddOptions)

Open
#1,144 0 comments 0 reactions 0 assignees View on GitHub
Needs: Triage (Functions)
Dominant language
C#
Stars
215
Forks
61
Avg merge
21h 4m
Merged PRs (30d)
6

Description

## Summary

When a PowerShell 7.4 Functions app loads **both** `Az.Accounts` 5.5.1 and `PnP.PowerShell`, any PnP cmdlet that builds an HTTP client (e.g. `Connect-PnPOnline`) throws a `System.MissingMethodException` inside `PnP.Framework`. Downgrading to **`Az.Accounts` 5.5.0** resolves it.

This has been reported by multiple customers. Filing as an advisory so others hitting the same exception can find the cause and workaround, and to flag a possible assembly-isolation issue in the worker.

## Exact 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 Microsoft.Extensions.DependencyInjection.HttpClientFactoryServiceCollectionExtensions.AddHttpClient(IServiceCollection services, String name, Action`1 configureClient)
at PnP.Framework.Http.PnPHttpClient.AddHttpClients(IServiceCollection collection, String UserAgent)
at PnP.Framework.Http.PnPHttpClient.BuildServiceFactory()
at PnP.Framework.Http.PnPHttpClient..ctor()
...
at PnP.PowerShell.Commands.Base.ConnectOnline.ProcessRecord()
```

## Root cause

The two modules ship conflicting `Microsoft.Extensions.*` assemblies that get co-loaded into the worker process:

| Assembly | Source | Version |
|---|---|---|
| `Microsoft.Extensions.Http` | PnP.Framework (bundled with PnP.PowerShell 3.2.0) | **8.0.0.0** |
| `Microsoft.Extensions.Options` | Az.Accounts **5.5.1** | **10.0.0.0** |

`Microsoft.Extensions.Http` 8.0.0.0 was compiled against the `AddOptions(IServiceCollection)` overload, which is not present in the `Microsoft.Extensions.Options` 10.0.0.0 that resolves in the worker → `MissingMethodException`.

Confirmed by changing only the `Az.Accounts` version (everything else identical):

| `Az.Accounts` | `Microsoft.Extensions.Options` loaded | Result |
|---|---|---|
| 5.5.1 | 10.0.0.0 | ❌ `MissingMethodException` |
| 5.5.0 | 8.0.0.0 | ✅ works |

## Reproduction

`requirements.psd1`:

```powershell
@{
'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'
}
```

In an HTTP-triggered function:

```powershell
Import-Module Az.Accounts
Import-Module PnP.PowerShell
Connect-PnPOnline -Url 'https://contoso.sharepoint.com' -ClientId '' -ClientSecret ''
# -> System.MissingMethodException in PnP.Framework.Http.PnPHttpClient.AddHttpClients
```

Both modules are required to reproduce — `Az.Accounts` alone does not load `Microsoft.Extensions.Http`; `PnP.Framework` supplies the `Http` 8.0.0.0 assembly and is the caller of `AddHttpClient`.

## Workaround

Pin `Az.Accounts` to **5.5.0** in `requirements.psd1`:

```powershell
'Az.Accounts' = '5.5.0'
```

## Environment

- Functions runtime: 4.1048.200.26180 (Core Tools 4.12.1)
- Worker: PowerShell 7.4.13 (.NET 8)
- `FUNCTIONS_WORKER_RUNTIME_VERSION`: 7.4
- Managed dependencies enabled

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the requirements.psd1 reproduction and the HTTP-trigger entry point that imports Az.Accounts and PnP.PowerShell, then run Connect-PnPOnline with the listed versions. The issue names no worker file or test and does not define a concrete change; done would require a confirmed worker-side resolution or an explicit decision to document the incompatibility and workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, powershell
Domain
backend, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.