powershell: [BUG] PnP and Azure functions assembly conflict. Could not load type 'Microsoft.Extensions.Logging.Abstractions.Internal.NullScope' from assembly 'Microsoft.Extensions.Logging.Abstractions'
Reporting an Issue or Missing Feature
This is an issue related to PnP using a conflicting assembly dependency than what
the Azure functions service loads by default. To be more specific, the issue occurs for us
with the module Microsoft.Extensions.Logging.Abstractions on each call of
Connect-PnPOnline. PowerShell 7.2 on Azure functions automatically loads
version 3.0.3.0 while the one included with PnP is 2.2.0.0. I have tried many
potential resolutions but have been unable to fix (Wrapping in ThreadJob does not work).
The one solution about downgrading from 7.2 to 7.0 is not an option for us, as we require
7.2 for its functionalities. Due to this issue, we are unable to rely on PnP for our needs at
the moment. If a fix for PnP in this scenario is possible, please do. If not, then notify of any
possible workarounds. This problem had me stumped for a while, so anything that can be
done about it is appreciated.
Expected behavior
Successful connection via Connect-PnPOnline cmdlet.
Actual behavior
An error related to a module in Azure functions:

Steps to reproduce behavior
- Create an Azure functions app version 4.0 and set it to use PowerShell 7.2
- Add PnP.PowerShell 1.10.0 to the requirements.psd1 file.
- Create a basic function that just tries to execute
Connect-PnPOnline. Ensure it logs error info. - Deploy the function to the cloud and execute via your API. (<app_url>/api/<func_name>)
- Wait a bit for logs to save, then go to monitor log menu for that function.
- View its logs and observe error.
NOTE: To reproduce, ensure code is run in the cloud within an Azure function. Running Connect-PnPOnline
locally will likely NOT cause an error. (The Azure assemblies won’t be loaded)
What is the version of the Cmdlet module you are running?
PnP.PowerShell 1.10.0, PowerShell Core 7.2
Which operating system/environment are you running PnP PowerShell on?
- Linux
- MacOS
- Windows
- Azure Cloud Shell
- Azure Functions
- Other : please specify
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 8
- Comments: 89 (4 by maintainers)
Commits related to this issue
- Temp fix for bug https://github.com/pnp/powershell/issues/2136#issuecomment-1413754123 — committed to ACHPER-Victoria/PnPUserProfileSync by Clam- 4 years ago
Hello all on this thread, we are looking into fixing this for Azure functions. Is more complex than we initially thought. It is surely at the top of our minds and a priority issue for us. Will try to fix it asap but can’t provide an ETA at this point.
To downgrade your function app from
PowerShell 7.2toPowerShell 7.0, follow these steps:Prerequisites:
Az.FunctionsandAz.Resources, which can be downloaded from the PowerShell Gallery.For a Windows function app
For a Linux function app
If you have any questions on why
PowerShell 7.0is"~7", please see https://github.com/Azure/azure-functions-powershell-worker/issues/885The
PowerShell 7.2language worker with the fix will start rolling out January 3rd, and it is expected to complete in one or two weeks. In the meantime, we are committing to provide support for the apps that are onPowerShell 7.0until this deployment completes./cc @anirudhgarg @anatolib @MadhuraBharadwaj-MSFT @michaelpeng36 @VpOfEngineering
Barring any issues, we should be fully rolled out by the beginning of next week.
Just tested this in an environment which has version
4.15.x.x, works perfectly fine !To fix this issue in your environment, please wait till the fix is there. I am guessing it will be available very soon worldwide.
I tested this in a resource group which is in
North Europeregion.Once the fix is available, you will need to update the PnP PowerShell to the latest nightly builds.
You need to explicitly specify the version number like
2.0.1-nightlyor later. The code will keep working as it is.Once a major release of PnP PowerShell is done, you can also specify it as a wildcard entry
2.x@KoenZomers if the solution proposed by @Micael-stack is suitable while you work with the PG and towards .NET 6 that would make a lot of us very happy!
Hi, I have created a pull request. I did a fork too, if it isnt approved so here it is :
https://github.com/Micael-stack/powershell/tree/fix/support-powershell7.2-azure-function
Instructions to get your own files :
Clone the git branch mentionned here
Run the powershell script in “.\Build\Build-Debug.ps1”
. .\Build\Build-Debug.ps1At the end of the script, there should be a module folder in your Documents/Powershell/Modules/Pnp.Powershell
Zip it, and upload it to your azure function, if not in git push setup ( I use the powershell tool in azure portal and upload the zip here :
Reference the powershell module in your code like this :
Import-Module .\Pnp.PowerShell\PnP.PowerShell.psd1That’s it, you should be running with no problems!
Thanks!
So I fixed it… by rebuilding Pnp.Powershell and Pnp.Framework. Updated refs to all Microsoft.Extensions.* from 2.2.0 to 3.0.3.0
PnP.Framework.csproj:
PnP.PowerShell.csproj:
I rebuilded a local module and uploaded it to my Azure function, so no more managed dependencies… referencing directly the module in scripts.
It would be good to know when the next major release of PnP will be out that works with the Azure fix. Some clients don’t like to use nightly versions in production 😃 thanks!
The Functions version
14.15.1deployment that was supposed to start on1/17/23has been delayed. However, the deployment started rolling out today1/23/23, and it is expected to be completed by the beginning of next week if no blocking issues are found./cc @anirudhgarg @AnatoliB @MadhuraBharadwaj-MSFT @michaelpeng36 @VpOfEngineering
Going to close this issue. It has been fixed from Microsoft side when using Az function 4.15.x or later version. To use PnP PowerShell, as we mentioned, please use the latest 2.x.x-nightly builds.
@desmay - no idea if this has been fixed for Azure Gov, but you can reach out to Microsoft support/PG for more information on this.
We have no ETA on the major release of PnP PowerShell as of now.
If you are not running a consumption plan, but under an app service plan, I ran into a weird issue and found a workaround. I was on a B2 sku and kept getting the nullscope error. I was not downgrading my ps version due to other production functions running on the same app plan. Maybe Azure gov does not back patch existing hosts or not fully finished yet. To make it work, upgrade your plan to a PV2/V3 and it will move it to a new host which should have the patched runtime. I verified it worked, then moved it back to a B2 plan which was put on a host that was patched as well.
The
PowerShell 7.2language worker which is being deployed with4.15.1updatesMicrosoft.Extensions.Logging.Abstractionsto version6.0.3. If the workaround was applied to thePowerShell 7.0language worker, then this should continue to work as no changes has been introduced to this version given that it has reached EOL.@KoenZomers – Could you please comment on next steps after
4.15.1completes rolling out? Thank you.@Ofer-Gal What are you trying to achieve? To role back to version 7.0 you can use a PowerShell script.
Or you can see the FUNCTIONS_WORKER_RUNTIME_VERSION locally in VSCode in the local.settings.json file.
The Functions release with the fix for the
PowerShell 7.2language worker has been delayed. Currently, the release is set to start deploying on January 17th, 2023 and it is expected to be completed in one or two weeks if no blocking issues are found. I will continue to update this issue with the deployment status as more information becomes available. Thank you.No worries @BeekvanV, we’re working closely with the Product Group for a solution on this. We’re currently testing a resolution for this internally. Thus far things are looking well. It will not be that your current Azure Functions will stop working on December 3rd. The permanent resolution for this will follow in January or February as things look like now.
I see. Thanks for elaborating. For the current version that might work, but we’re aiming to go for .NET 6 support in the next version and there this would not be an option. I’ll discuss it in our team if we could apply your suggestion in the meantime.
@gautamdsheth , do you have any idea if the pnp.powershell is adapted on this issue or when it will happen? Thanks for your feedback!