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:
@{
'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:
Import-Module Az.Accounts
Import-Module PnP.PowerShell
Connect-PnPOnline -Url 'https://contoso.sharepoint.com' -ClientId '<id>' -ClientSecret '<secret>'
# -> 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:
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
Summary
When a PowerShell 7.4 Functions app loads both
Az.Accounts5.5.1 andPnP.PowerShell, any PnP cmdlet that builds an HTTP client (e.g.Connect-PnPOnline) throws aSystem.MissingMethodExceptioninsidePnP.Framework. Downgrading toAz.Accounts5.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
Root cause
The two modules ship conflicting
Microsoft.Extensions.*assemblies that get co-loaded into the worker process:Microsoft.Extensions.HttpMicrosoft.Extensions.OptionsMicrosoft.Extensions.Http8.0.0.0 was compiled against theAddOptions(IServiceCollection)overload, which is not present in theMicrosoft.Extensions.Options10.0.0.0 that resolves in the worker →MissingMethodException.Confirmed by changing only the
Az.Accountsversion (everything else identical):Az.AccountsMicrosoft.Extensions.OptionsloadedMissingMethodExceptionReproduction
requirements.psd1:In an HTTP-triggered function:
Both modules are required to reproduce —
Az.Accountsalone does not loadMicrosoft.Extensions.Http;PnP.Frameworksupplies theHttp8.0.0.0 assembly and is the caller ofAddHttpClient.Workaround
Pin
Az.Accountsto 5.5.0 inrequirements.psd1:Environment
FUNCTIONS_WORKER_RUNTIME_VERSION: 7.4