-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Not able to connect to Azure with Az.Accounts version 2.12.3 (get_SerializationSettings) from within Visual studio code / Azure Automation runbook on Hybrid Worker #21960
Comments
Can confirm. Have the same problem. |
Same here |
Ditto... |
Same here. It fails i Terminal as well PSVersion 5.1.22621.963 |
Hi thanks for reporting. We are aware of this compatibility issue and are working with PowerShell to get it fixed. Let me summarize the problem here: SymptomThe Windows PowerShell 5.1 terminal provided by the PowerShell VS Code extension cannot import Az.Resources v6.6.1. The error you receive is: "Register-AzModule : The type initializer for 'Microsoft.Azure.Commands.Common.AzModule' threw an exception". Root causeThe Windows PowerShell 5.1 runtime preloads the PowerShellEditorServices module, which depends on Newtonsoft.Json 11.0. This issue is similar to one that caused a conflict with Az.Accounts. Workarounds
SolutionWe have contacted the team who maintains the PowerShellEditorServices module for an update of the library. According to them, it is inherited from the OmniSharp library that provides our LSP layer. We are in the process of following up with Omnisharp, which is part of .NET foundation. |
Is it possible that it doesn't work in PS7 ?
I had to downgrade the two mentioned Az modules (Az.Accounts v2.12.1, Az.Resources v6.6.0) to make it work. |
Can't wait to upgrade to PowerShell 7.0 to leave the nightmare of the newtonsoft dll. See as well https://learn.microsoft.com/en-us/powershell/scripting/dev-cross-plat/resolving-dependency-conflicts?view=powershell-7.3. However Azure Automation only support 5.1 for production. PowerShell > 7.1 is already for I think over 1 year in preview (so we cannot switch to core because of it being in preview still). As well as some M365 power shell libraries are not compatible yet with PowerShell core. |
Not a VSCode only issue: |
Note that because of the retiring run as accounts this should be the replacement. Downgrading to a earlier version does not seem a very stable mitigation. I also noticed that a brand new Automation account is leveraged with a lower version "out of the box" which is not returned after getting the module through the gallery. |
I am also facing the same issue using Automation Account runbooks with PS version 5. |
I did the install of Powershell 7 and also Downgrade Az modules but now I'm facing a different issue. Somebody could help me please? Bug running a powershell script as Administrator on Powershell 7 Import-Module Modules
|
Just another +1 here, having the same issue with AutomationAccount Runbooks running on a hybrid worker VM. My only option is to use 5.1 and therefore downgrade the module, but this also causes the keyvault module to fail due to version incompatibilities so I've had to downgrade that 2x also. |
What is the latest status of this issue? |
+1 same issue here :(
|
Hi, Facing the same issue. |
We've seen this issue without using Hybrid Workers; pure Azure Automation with Managed Identity (no RunAs usage). |
Using Windows PowerShell is not a workaround. Downgrading to Az.Accounts 2.12.1 and Az.Resources 6.6.0 also fails to resolve. This issue gives more details on the scenarios in which I've reproduced the issue: Everything works in v7, but that's just not a solution when scripting for two major MSFT platforms: Endpoint Manager MDM scripts, and Azure Automation. |
Hi, I'm glad to announce the issue was resolved, please see this comment for more information. For maintenance purpose I'm closing this issue. If you need us to follow up on anything please reply in #21647 . Thanks. |
I am glad you solved the Azure automation issue but I am not sure why you closed this issue. This issue seems to be mostly based around the issue that was not fixed. “And for the conflict with the vscode terminal provided by the PowerShell extension, unfortunately the issue is still there. We couldn't get response from the maintainer of OmniSharp/csharp-language-server-protocol , who we hope can update their dependency of Newtonsoft.Json hence resolve the conflict. I'll update the thread once we get any updates.” |
Hey @mark3grahams , yes, this issue was about vscode originally. But the conversation quickly got mixed by the other issue with Azure Automation. I closed this one purely to avoid confusion and duplication. |
Also getting this issue Az.Accounts version 2.12.5, PS 5.1 windows 10 (VSCode) |
@jpawlowski Some off topic advice / experience sharing from using Automation Account with PowerShell 7.2 for some time:
I'm considering checking out Function Apps as a replacement. I've been a long time Automation Account user, but these reliability problems and my poor Azure support experience kind of forces me to look for something else. At least for workloads were realiability is a concern, like with log ingestion. |
@o-l-a-v, thank you for sharing these insides. Sounds like I should reevaluate to keep the PS 5.1 workarounds and compatibility in the code. I was hoping to make the code easier by removing 5.1 backwards compatibility, especially for performance and memory optimization that's really hard to achieve sometimes in PS 5.1. I still want to try it but might now be prepared to go back to PS 5.1, but at least be prepared to switch to PS 7.2 by cleaning up the child runbook dependency. Azure Functions are not really a replacement for Azure Automation, it really depends on the specific use case. Sometimes you might even need both in combination. Azure Functions are meant to perform quick actions like within a few seconds and can give direct output back to the caller for that reason. However, it doesn't work for long-running tasks, like for user provisioning or something that requires further processing. Azure Automation has its domain and issues shall hopefully be fixed. The support experience you describe may be different when you have access to primer support, or a direct contact to the Microsoft support organization and product groups (my experience). |
I provided a work-around for these persistent NewtonSoft.Json conflicts we have seen rear their head time and time again between the HybridWorker modules, Az.* Modules, Graph.* Modules, and now VSCode in my post above back in February. It became a big hassle to try to keep specific versions with missing functionalities across the board. My team has been leveraging this workaround I came up with in a production environment for 2 different automation platforms (AzureAutomation HybridWorkers for 1, a 3rd Party Platform for the other) which both leverage PowerShell (under different executables) to work-around the NewtonSoft.Json assembly conflict. This assembly redirection is even mentioned by Microsoft documentation here as a potential solution which I found after I had implemented it:
The only quirk is some modules have to be imported in a specific order to be happy if more than 1 is used in your script:
I have only had to re-apply the bindingRedirect once when the app was updated and it was overwritten. I am surprised the work-around has not gotten much traction since I have shared... Today I tested this with the VSCode conflict by adding the redirect to the powershell.exe.config file located @ "$PSHOME\powershell.exe.config" and it does also resolve this issue. I decided to write up a script to allow others to easily patch their own app.config file and insert the same redirection without having to do so manually. Find that script here The script will back up the current configuration file to $ENV:temp, take ownership and grant your user FullControl, then insert the XML into the config, then rollback the ownership/permissions. After that you should be NewtonSoft.Json-assembly-conflict-free in new PowerShell sessions. Here is what to expect to see when running the PS1: Afterwards I started a new PowerShell Extension session in VSCode, Ran Import-Module Az.Accounts, and connected without issue as you can see here: DISCLAIMER: |
This workaround only helps if you don't want to do fancy serverless things, which I think is what most people want to do nowadays (if there is no on-prem dependency). I've not been using hybrid workers intensively but wonder why people would still stick with Windows PowerShell on it. I'd be curious to learn more should you be willing to share some aspects. For local issues on the workstation, it is just becoming too cumbersome and complicated to fix good old PowerShell 5.1. Microsoft has clearly moved on and doesn't care about PS 5.1 anymore; it is just that they can't remove it as a default on Windows (yet). Sadly, most people are not aware of the complex situation (I've been explaining this to customers quite often within the last few months). VSCode is designed to be used with PowerShell Core. I personally would recommend everybody to leave Windows PowerShell Desktop version behind. I know that for development of code that should still work on PowerShell 5.1, this comes with some challenges to handle the backwards compatibility. I've been able to handle this okay to be honest, and PSScriptAnalyzer can be taught to help with some warnings for backwards compatibility. In Microsoft Land (maybe not limited to that), I do think they embraced developing inside a (Linux) devcontainer as a standard which means that you will need to use PowerShell Core. I personally also wouldn't want to go back to only local development either (or switch to a Windows PC, since I'm using a Mac for decades already). Taking all of this into consideration, you may not expect much from anyone in Microsoft to fix stuff in any area that is still using PowerShell 5.1. Any investment is in PowerShell Core and even though nobody tells you that officially, you may assume that they often simply would like to send a reply like "move to the newest version". They will not do this as an official statement anytime soon for many reasons. That being said, I have decided to stop making own investments (timewise and moneywise) into PowerShell 5.1, too. I know this sounds like an unpopular decision to make, but you must make that sooner or later. ... and all Microsoft SaaS related modules have now been updated in a way so they can be used in PowerShell Core and are multi-platform compatible. This was different like 2 years ago. But the situation has changed for the better in that regard and the journey of PowerShell 5.1 is about to come to a dead end. |
I totally agree with everything you've said here. The serverless aspect makes sense as this wouldn't be applicable. I've been slowly adjusting all our automation to be compatible with PowerShell Core. Right now a lot of our runbooks dot-source other run books. I'm working on turning some of those children runbooks into functions in a module, and making other children runbooks use basic variables over complex ones so we can leverage start-azautomationrunbook. Anything new I've written I make sure is written in a way that can be used with PowerShell Core. One problem is I don't think our 3rd party automation platform has the option of using Core, but with 5.1 EOS coming up in a few years I'm sure that will change as well. Our goal is to use Core for sure. Unfortunately we don't have the resources to make the migration our #1 priority but it is something we are iterating towards. |
So there is the upcomming breaking change:
And this case is still valid for me in VSCode, which still trows the error on Connect-AZAccount when using 3.0.2 of AZ Accounts. |
Was getting the same error for couple of months and finally got time to have a closer look. |
This is not a good solution anymore, as AZ.Accounts will have a breaking change soon. |
Can't agree more - but I'm trying to push here with my contacts at Microsoft and the team behind - stay tuned! |
Any news on this? |
#26206 Related issues |
@michaelmsonne Do you have an update? |
I have pinged the team at Microsoft yesterday again, in my Teams chat I have... |
I also opened my MS connections last week as this is getting more and more a problem in our enterprise environment. (250000 employees, our service completely on azure) |
Update from my contacts: "We will update the issue progress on the GitHub issue tomorrow to facilitate everyone to know the progress". The issue is a bit tricky as I can understand on the team. The team is currently considering how to decouple these tricky issues. Lets see tomorrow! |
The reply is a bit late because the engineers are dealing with some urgent issues. I look forward to @isra-fel giving a progress reply soon. |
I was investigating in the issue with vscode, the one thing that's super suspicious is this error in the fusion log (full version).
The log was captured when Az.Accounts was imported to the integrated terminal. It showed the process of binding My assumption is that the two assemblies in the fusion log are these two from the preloaded modules
pasm: https://gist.github.com/isra-fel/0c503fbccbf301e8c42135dfa47e4408 These are my findings for now. |
@isra-fel hank you for looking deeper into it. Very appreciated that someone now starts to really look into this issue to get it fixed. |
We plan to update every two weeks or monthly, although we may not be able to give an ETA |
Hi @Alex-wdy , Is ther any updates the last month or? This is a very bad bug på deal with all the time :( |
Hey, we really need an update to this! This is not tolerable and keeps us back in everyday work! |
This consistency MS manage with screwing these Az PS modules up is impressive. |
They are never fixing this. The heat death of the universe will come quicker. |
OK so from the author of the PowerShell extension's perspective
I will conclude this issue as below - it's a limitation of PS 5.1 that there's no solution for assembly isolation. The known workarounds are
|
Description
With the latest version of Az.Accounts version 2.12.3 we face an issue when running the Connect-AzAccount command in PowerShell 5.1.3 terminal in Visual Studio code. The previous version(s) 2.12.2 did not throw an error.
The error occurs with fully installed AZ module latest version 10.0.0.0 or only having the Az.Accounts module installed.
Issue script & Debug output
Environment data
Module versions
Error output
The text was updated successfully, but these errors were encountered: