Closed desmay closed 1 year ago
This is a known issue in the combination of PnP.PowerShell and Azure Functions version 4. A fix for Azure functions is currenlty rolling out.
You can find more information in issue #2136 including possible workarounds.
@reusto I think this maybe different. I have Azure runtime updated to 4.15.XX and can run an http trigger function with no issues on same app service. Its only if called from a durable function where I have the issues with PNP
Oh okay, interesting and good to know would have wanted to use it in a similar setup soon as well. :/
@desmay @reusto I also had/have this issue (with Durable Functions) but in my scenario, I was able to resolve it (I hope!)
Environment:
In my case, I was getting the above error but for Microsoft.Extensions.DependencyInjection.Abstractions.dll
Turns out PnP.PowerShell bundles version 6 of the above DLL and Az.Resources has 2. For some reason in a Durable Functions this causes issues as running the code locally (via PowerShell), the issue does not present.
As with previous fixes, I tried setting WEBSITE_LOAD_USER_PROFILE = 1
this didn't help the initial error.
I also tried setting PSWorkerInProcConcurrencyUpperBound
and FUNCTIONS_WORKER_PROCESS_COUNT
to 1 to ensure there was only 1 run space. This didn't help.
I tried 32-bit vs 64-bit this didn't help.
I tried to order my modules that were listed in resources.psd1, but it turns out that hash table is processed by the underlying .net code randomly.
Next, I turned off managedDependency
in host.json
, using save-module
to include a modules directory with all the modules I needed in the function. I then used import-module
to import the modules in the order I wanted in profile.ps1
. This didn't work either.
Turns out, PnP.PowerShell doesn't load any dependencies until a command is run. So, in profie.ps1
I just ran the following invalid command to trigger the DLL load:
try { Connect-PnPOnline -ValidateConnection -Url https://localhost -CurrentCredentials } catch {}
This enabled PnP.PowerShell to work without issues. But (there's always a but), the AzStorage
I was using stopped working. The module was found but failed to load any commands. I actually wasn't able to resolve this, so I wrote my own wrapper using the Storage RestAPI.
In the end, I didn't need to modify anything except:
requirements.psd1
WEBSITE_LOAD_USER_PROFILE = 1
to the Azure Functions configuration. I believe this is needed for the Thumbprint
to workIf you don't have AzStorage you've probably got a similar scenario that you may be able to troubleshoot using the steps above.
Greg
@oobegreg Thanks for detailed steps. I will give this a try later this week.
Closing for now. Can you please update to the latest release 2.1.x
if necessary, however you will need PS 7.2 or later to benefit from all the bug fixes and improvements.
PS5 support has been dropped in the new release.
Feel free to reopen if the issue persists. Thanks.
Not sure how this was resolved. I have the same issue using PS 7.3 with PnP 2.1.1 running locally. (Azure functions online is ok). I believe the issue is that it is not loading .Net6 for some reason. Anyone else?
@ChrisNotABot that's annoying to hear. I haven't had the chance to update to 2.* yet due to other commitments.
@veronicageek could you please re-open?
@oobegreg - We have bumped a lot of our underlying dependencies in the 2.1.1 update as things either get deprecated or not worked on anymore by Microsoft. PnP PowerShell 1.12.0
is still available if there's a need for PS5 or compatibility with other modules, while Microsoft updates their own modules.
But unfortunately, we have no control over other modules, and nothing we can really do if PnP PowerShell is working on its own.
In case it helps: https://pnp.github.io/powershell/articles/azurefunctions.html
Reporting an Issue or Missing Feature
Error when attempting to connect via certificate.
Connect-PnPOnline -Url "https://$tenant-admin.sharepoint.com" -Thumbprint $certThumbprint -ClientId $clientId -Tenant $tenantId
Expected behavior
Establish connection to tenant
Actual behavior
Connection fails Result: ERROR: Could not load file or assembly 'Microsoft.Extensions.Logging.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Could not find or load a specific file. (0x80131621)
Steps to reproduce behavior
Create a basic durable function and in the activity function create connection to PNPOnline and invoke with script below
Invoke-DurableActivity -FunctionName 'getGroups'
What is the version of the Cmdlet module you are running?
2.013.
Which operating system/environment are you running PnP PowerShell on?