Giter Club home page Giter Club logo

Comments (4)

RRanks avatar RRanks commented on June 12, 2024

Requirements.psd1
@{
# For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'. Uncomment the next line and replace the MAJOR_VERSION, e.g., 'Az' = '5.'
#'Az' = '11.
'
'AzAuth' = '2.'
'AzTable' = '2.
'
'Az.Accounts' = '2.'
'Az.Resources' = '6.
'
'Az.Storage' = '5.'
'Az.KeyVault' = '4.
'
#'AzureAD' = '2.'
'ExchangeOnlineManagement' = '3.
'
'MicrosoftTeams' = '4.'
#'Microsoft.Graph' = '2.15.0'
'Microsoft.Graph.Groups' = '2.
'
'Microsoft.Graph.Authentication' = '2.'
'Microsoft.Graph.Users' = '2.
'
}

from azure-functions-powershell-worker.

andystaples avatar andystaples commented on June 12, 2024

Hi @RRanks,
Upon initial review, it appears most likely to me that your issue is a dependency conflict within your modules, and not a return of the platform issue from #1010. This type of error is somewhat common in PowerShell functions which use more than a handful of dependent packages, due to PowerShell loading all modules and their required binaries into the default assembly load context.
We are working on publishing a user guide for this scenario, but our general recommendation for avoiding/preventing these types of errors is as follows:

  1. Figure out which of the modules from requirements.psd1 utilize the .dll which is in conflict (in this case, Microsoft.Identity.Client). You can utilize Save-Module on your local machine to download the modules and examine their contents to figure out if they are using this dll and which version they use.
  2. Pin these modules to a specific minor version to prevent the managed dependencies feature from auto-upgrading them and introducing breaking conflicts.
  3. In profile.ps1, explicitly import each module using Import-Module with the -RequiredVersion parameter. Import the modules in order from highest Microsoft.Identity.Client version to lowest.
  4. Run the function app. If you are still getting errors, take note of which Import-Module statement is failing, and move it higher in the list.

If you are unable to resolve the issue using these steps, you may have a circular dependency conflict. At this point, there are some further alternatives.

Either

a) You could try running fragile modules in windows compatibility mode. This will isolate those modules into their own powershell instance and therefore, their own assembly load context. Instructions and disclaimers for this approach can be found here

or

b) Splitting the function app into multiple apps each using minimal sets of modules can help prevent modules from conflicting with each other.

If none of these approaches are successful or acceptable, please reach out to our Azure support staff who may be able to further assist. https://learn.microsoft.com/en-us/azure/azure-portal/supportability/how-to-create-azure-support-request

from azure-functions-powershell-worker.

RRanks avatar RRanks commented on June 12, 2024

@andystaples

Hi @RRanks, Upon initial review, it appears most likely to me that your issue is a dependency conflict within your modules, and not a return of the platform issue from #1010. This type of error is somewhat common in PowerShell functions which use more than a handful of dependent packages, due to PowerShell loading all modules and their required binaries into the default assembly load context. We are working on publishing a user guide for this scenario, but our general recommendation for avoiding/preventing these types of errors is as follows:

  1. Figure out which of the modules from requirements.psd1 utilize the .dll which is in conflict (in this case, Microsoft.Identity.Client). You can utilize Save-Module on your local machine to download the modules and examine their contents to figure out if they are using this dll and which version they use.
  2. Pin these modules to a specific minor version to prevent the managed dependencies feature from auto-upgrading them and introducing breaking conflicts.
  3. In profile.ps1, explicitly import each module using Import-Module with the -RequiredVersion parameter. Import the modules in order from highest Microsoft.Identity.Client version to lowest.
  4. Run the function app. If you are still getting errors, take note of which Import-Module statement is failing, and move it higher in the list.

If you are unable to resolve the issue using these steps, you may have a circular dependency conflict. At this point, there are some further alternatives.

Either

a) You could try running fragile modules in windows compatibility mode. This will isolate those modules into their own powershell instance and therefore, their own assembly load context. Instructions and disclaimers for this approach can be found here

or

b) Splitting the function app into multiple apps each using minimal sets of modules can help prevent modules from conflicting with each other.

If none of these approaches are successful or acceptable, please reach out to our Azure support staff who may be able to further assist. https://learn.microsoft.com/en-us/azure/azure-portal/supportability/how-to-create-azure-support-request

I FOUND THE ISSUE >> Seems to be the file location changes. And unable to use the "-RequiredVersion" parameter to call an older version

None of the above resolved the issue.. here is what I have found...

I setup a function with just Import-Az.Accounts using the older required version that was working with the previous issue 5months ago. V2.13.2.
AzAccountFunc Test1

It then errored saying it was using V2.16, and Microsoft confirmed it will import the latest version of Az.Accounts no matter what version I add the required value as.
However... The V2.16.0 does not have the same internal folder structure so the fix in #1010 - Is not causing this issue in.. the new version as all the files are in the "netstandard2.0" folder not "netcoreapp2.1" and not "netcoreapp3.1".

Without the patch from the #1010 - It does not work however.. the fix now needs to be updated to the correct path:

Import-Module Az.Accounts
$azAccountsLibPath = Join-Path (Split-Path (Get-Module Az.Accounts).Path -Parent) "lib"
Add-Type -AssemblyName (Join-Path $azAccountsLibPath "netstandard2.0" "Microsoft.IdentityModel.Abstractions.dll")
Add-Type -AssemblyName (Join-Path $azAccountsLibPath "netstandard2.0" "Microsoft.Identity.Client.dll")
Add-Type -AssemblyName (Join-Path $azAccountsLibPath "netstandard2.0" "Microsoft.Identity.Client.Extensions.Msal.dll")
Connect-AzAccount -Identity

error when trying to use RequiredVersion: V2.13.2
2024-04-02T03:44:56Z [Error] ERROR: Could not load file or assembly 'C:\home\data\ManagedDependencies\2404020332440659854.r\Az.Accounts\2.16.0\lib\netcoreapp2.1\Microsoft.Identity.Client.dll'. The system cannot find the file specified.

More screen shots attached..

AzAccountsv2 16 0
netcoreapp2 1Folder
netstandard2 0Folder

from azure-functions-powershell-worker.

RRanks avatar RRanks commented on June 12, 2024

Oh I also dropped the Graph connections back down to the 5 months ago version.. not tested upgrading them again yet.
'Microsoft.Graph.Groups' = '2.9.1'
'Microsoft.Graph.Authentication' = '2.9.1'
'Microsoft.Graph.Users' = '2.9.1'
'Microsoft.Graph.Education' = '2.9.1'
'Microsoft.Graph.Calendar' = '2.9.1'

from azure-functions-powershell-worker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.