Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] - Azure Durable Function - PowerShell 7.2 Issue #2823

Closed
5 tasks
desmay opened this issue Feb 15, 2023 · 9 comments
Closed
5 tasks

[BUG] - Azure Durable Function - PowerShell 7.2 Issue #2823

desmay opened this issue Feb 15, 2023 · 9 comments
Labels
azure-automation Includes Azure Functions or Azure Runbooks bug Something isn't working

Comments

@desmay
Copy link

desmay commented Feb 15, 2023

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?

  • Windows
  • Linux
  • MacOS
  • Azure Cloud Shell
  • [x ] Azure Functions
  • Other : please specify
@desmay desmay added the bug Something isn't working label Feb 15, 2023
@reusto
Copy link
Contributor

reusto commented Feb 15, 2023

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.

@desmay
Copy link
Author

desmay commented Feb 15, 2023

@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

@reusto
Copy link
Contributor

reusto commented Feb 15, 2023

Oh okay, interesting and good to know would have wanted to use it in a similar setup soon as well. :/

@veronicageek veronicageek added the azure-automation Includes Azure Functions or Azure Runbooks label Feb 16, 2023
@oobegreg
Copy link

oobegreg commented Mar 7, 2023

@desmay @reusto I also had/have this issue (with Durable Functions) but in my scenario, I was able to resolve it (I hope!)

Environment:

  • Azure Functions version: 4.15.2.20177
  • PnP.PowerShell version: 2.0.35-nightly

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:

  • Remove AzStorage from requirements.psd1
  • Replace AzStorage with my own RestApi implmentation
  • Added WEBSITE_LOAD_USER_PROFILE = 1 to the Azure Functions configuration. I believe this is needed for the Thumbprint to work

If you don't have AzStorage you've probably got a similar scenario that you may be able to troubleshoot using the steps above.

Greg

@desmay
Copy link
Author

desmay commented Mar 8, 2023

@oobegreg Thanks for detailed steps. I will give this a try later this week.

@veronicageek
Copy link
Collaborator

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.

@ChrisNotABot
Copy link

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?

@oobegreg
Copy link

@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?

@veronicageek
Copy link
Collaborator

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
azure-automation Includes Azure Functions or Azure Runbooks bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants