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

Microsoft.Graph.Authentication fails in Azure Automation Account due to a dependency on System.Runtime 8.0.0.0 #3151

Open
erobillard opened this issue Feb 20, 2025 · 7 comments
Assignees
Labels
Azure Automation type:bug A broken experience

Comments

@erobillard
Copy link

Describe the bug

The following 2 lines fail in an Azure Automation Account Runbook (7.2 runtime environment):
Connect-AzAccount -Identity
Connect-MgGraph -Identity

With the error:
Could not load file or assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

This was working with the following assemblies all on 2.25.0:
Microsoft.Graph
Microsoft.Graph.Authentication
Microsoft.Graph.Teams

Today the same lines fail with a tenant running these 3 DLLs on version 2.26.0

Expected behavior

The code should authenticate to Graph. All other Runbooks in this same Azure Automation Account succeed when authenticating with a client secret to retrieve a token, i.e.:

$response = Invoke-RestMethod -Method Post -Uri "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token" -ContentType "application/x-www-form-urlencoded" -Body $body

As soon as the Connect-MgGraph is required (in this case to add a member to a Shared channel in MS-Teams), authentication fails with the error as described.

How to reproduce

  1. Create and configure an Azure Automation Account to authenticate as a managed identity. Configure as Powershell, 7.2 runtime environment.
  2. Install these modules:
    Microsoft.Graph
    Microsoft.Graph.Authentication
    Microsoft.Graph.Teams
  3. Confirm the installed version is 2.26.0
  4. Create and execute a runbook with the lines:
    Connect-AzAccount -Identity
    Connect-MgGraph -Identity
  5. Watch it fail.

SDK Version

2.26.0

Latest version known to work for scenario above?

2.25.0

Known Workarounds

None I can find.

Debug output

Click to expand log ```
</details>


### Configuration

Azure Powershell 7.2 Runbook

### Other information

Someone compiled this with a dependency on System.Runtime 8.0 rather than the latest available to an Azure  Automation Account, and there's no way to force the version (i.e., set a -RequiredVersion parameter). 
@erobillard erobillard added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Feb 20, 2025
@erobillard
Copy link
Author

Related issue: #3147
In that case it appears that updating PowerShell resolved the issue, I don't believe this is an option with Azure Automation (7.2 it is).

@timayabi2020
Copy link
Contributor

Hi @erobillard apologies for that experience. There is an existing issue here azureautomation/runbooks#112, requesting that team to provide an option for 7.4. Meanwhile, you can downgrade to v2.25.0 or use Azure functions.

@timayabi2020 timayabi2020 self-assigned this Feb 21, 2025
@timayabi2020 timayabi2020 added Azure Automation and removed status:waiting-for-triage An issue that is yet to be reviewed or assigned labels Feb 21, 2025
@erobillard
Copy link
Author

Thanks @timayabi2020, a downgrade to 2.25.0 did resolve the issue as a workaround.

@svrooij
Copy link

svrooij commented Feb 21, 2025

Azure Automation is capped at PowerShell 7.2 which is built upon dotnet 6 which is officially out of support since Nov 12th 2024 🤔

I cannot believe they still don't provide PowerShell 7.4 (dotnet8) for Azure Automation....

@alpixdotro
Copy link

Workaround:

  1. Save-Module -Name Microsoft.Graph.Authentication -Path C:\temp\Modules -Repository PSGallery -MaximumVersion 2.25.0
  2. ZIP it
  3. Upload to Azure Automation, select runtime 7.2, and wait for import. It will overwrite 2.26.0 version and functionality will be restored.

@erobillard
Copy link
Author

You can also download modules from https://www.powershellgallery.com/packages/Microsoft.Graph/2.25.0

Rename the nupkg file to, for example Microsoft.Graph.zip, or remember to change the name as you upload it to Modules in the Azure Automation Account. Version 2.25.0 worked for me, you shouldn't need to go any earlier.

I also find things to be more stable when version numbers match within a namespace like Microsoft.Graph.*

@alexandair
Copy link
Contributor

A workaround is to enable Runtime environment experience (in public preview) and create a custom Runtime environment.

  1. Select Overview and then select Try Runtime environment experience.
  2. Under Process Automation, you will get the Runtime Environments (Preview)
  3. Create a new RE. Pick PowerShell 7.4 as runtime version and add needed Microsoft Graph PowerShell v2.26 modules as packages.
  4. Assign newly created custom Runtime environment to your runbooks that stopped working after you updated to Microsoft Graph PowerShell 2.26.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Azure Automation type:bug A broken experience
Projects
None yet
Development

No branches or pull requests

5 participants