Azure / deployment-stacks

Contains Deployment Stacks CLI scripts and releases
MIT License
87 stars 7 forks source link

Deployment stack setup issue #64

Closed Grant-Rc closed 1 year ago

Grant-Rc commented 2 years ago

Issue During Setup I got the following Error

Import-Module : Could not load file or assembly 'Microsoft.Azure.Management.ResourceManager, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Strong name validation failed. (Exception from HRESULT: 0x8013141A)
At C:\Users\crowegr\Downloads\AzDeploymentStacksPrivatePreview_Powershell\AzDeploymentStacksPrivatePreview\AzDeploymentStacksPrivatePreview.ps1:260 char:5
+     Import-Module -Name $modulePsdPath
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Import-Module], FileLoadException
    + FullyQualifiedErrorId : FormatXmlUpdateException,Microsoft.PowerShell.Commands.ImportModuleCommand

I Looked into the PowerShell file and found that there is a function function Enable-StrongNameVerificationSkip But this function is not called any where as you can see from the screen shot

image

Steps to reproduce the behavior:

  1. Open Powershell ISE as Administrator
  2. Run Set-ExecutionPolicy Bypass -Scope Process
  3. Set-Location to the extracted zip location
  4. Run .\AzDeploymentStacksPrivatePreview.ps1

Expected behavior Expecting the function "Enable-StrongNameVerificationSkip" to run so that this error doesn't occur

Full output

AzDeploymentStacks Private Preview
=============================================================
Manages installation of the cmdlets for the private preview 
build of Az.Resources which can be used to manage/deploy 
Deployment Stacks.

This script can perform multiple operations. Select the operation you'd like to perform:

   1. Install module in current Powershell session
   2. Install module system-wide
   3. Uninstall module (previous system-wide installs)

Note: When you install the preview module, the preview functionality 
      will override the official/public Az.Resources module functionality until 
      the Powershell session is closed (if option 1 is selected) or until the 
      preview module is uninstalled through this script (if installed through 
      option 2).

Which operation (1, 2, or 3)?: 1
This action will install the Deployment Stack cmdlet(s) to the current 
Powershell Session (prompt) so they can be previewed/tested.

Continue with install? (Y/N): y
Verifying Azure Powershell module availability...
Azure Powershell module verified!

Verifying you're logged into Azure...
Login verified!

Installing demo module 'Az.Resources'... (current session only)
Import-Module : Could not load file or assembly 'Microsoft.Azure.Management.ResourceManager, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Strong name validation failed. (Exception from HRESULT: 0x8013141A)
At C:\Users\crowegr\Downloads\AzDeploymentStacksPrivatePreview_Powershell\AzDeploymentStacksPrivatePreview\AzDeploymentStacksPrivatePreview.ps1:260 char:5
+     Import-Module -Name $modulePsdPath
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Import-Module], FileLoadException
    + FullyQualifiedErrorId : FormatXmlUpdateException,Microsoft.PowerShell.Commands.ImportModuleCommand

Repro Environment Host OS : Windows 10 image

Additional context This is the first Private Preview so let me know if there is anything missing, i have just to run the function manually to see if it work as i will rely on the community support.

bmoore-msft commented 2 years ago

@stuartko can you have a look?

@Grant-Rc - can you try the CLI and see if that installs ok on your machine?

bmoore-msft commented 2 years ago

@stuartko - any ideas?

jonclyde commented 2 years ago

Hi team, just to add - I'm having the same issue in both PowerShell and CLI as reported by @Grant-Rc above. Tested on two different machines, one of which was new and clean windows VM.

stuartko commented 2 years ago

@Grant-Rc : For the Powershell issue, can you run the following from the root Private Preview directory and try the installation again?:

.\bin\x64\sn.exe -Vr .\bin\modules\Az.Resources\Microsoft.Azure.Management.ResourceManager.dll

This will cause strong name verification to be bypassed for this particular assembly.

bmoore-msft commented 2 years ago

Install CLI MSI successfully and following tutorial I get the following image Thoughts?

@Grant-Rc - do you mind opening a new issue for this, it looks to be unrelated...

Grant-Rc commented 2 years ago

.\bin\x64\sn.exe -Vr .\bin\modules\Az.Resources\Microsoft.Azure.Management.ResourceManager.dll

here is my results from sunning this

.\bin\x64\sn.exe -Vr .\bin\modules\Az.Resources\Microsoft.Azure.Management.ResourceManager.dll

Microsoft (R) .NET Framework Strong Name Utility  Version 4.0.30319.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Verification entry added for assembly 'Microsoft.Azure.Management.ResourceManager,31BF3856AD364E35'

then I rain the script and still got error

AzDeploymentStacks Private Preview
=============================================================
Manages installation of the cmdlets for the private preview 
build of Az.Resources which can be used to manage/deploy 
Deployment Stacks.

This script can perform multiple operations. Select the operation you'd like to perform:

   1. Install module in current Powershell session
   2. Install module system-wide
   3. Uninstall module (previous system-wide installs)

Note: When you install the preview module, the preview functionality 
      will override the official/public Az.Resources module functionality until 
      the Powershell session is closed (if option 1 is selected) or until the 
      preview module is uninstalled through this script (if installed through 
      option 2).

Which operation (1, 2, or 3)?: 1
This action will install the Deployment Stack cmdlet(s) to the current 
Powershell Session (prompt) so they can be previewed/tested.

Continue with install? (Y/N): y
Verifying Azure Powershell module availability...
Azure Powershell module verified!

Verifying you're logged into Azure...
Login verified!

Installing demo module 'Az.Resources'... (current session only)
Import-Module : Could not load file or assembly 'Microsoft.Azure.Management.ResourceManager, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one 
of its dependencies. Strong name validation failed. (Exception from HRESULT: 0x8013141A)
At C:\Users\crowegr\Downloads\AzDeploymentStacksPrivatePreview_Powershell\AzDeploymentStacksPrivatePreview\AzDeploymentStacksPrivatePreview.ps1:260 char:5
+     Import-Module -Name $modulePsdPath
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Import-Module], FileLoadException
    + FullyQualifiedErrorId : FormatXmlUpdateException,Microsoft.PowerShell.Commands.ImportModuleCommand
Grant-Rc commented 2 years ago

NP, Done

harshpatel17 commented 2 years ago

This error is expected to fixed in the next Deployment Stacks release.

stuartko commented 2 years ago

@Grant-Rc : It's possible a reboot will be required after the sn.exe command is run. But my other thought is that group policy on your machine may be overwriting the disabled strong name verification flag.

Can you run "reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\StrongName\Verification\ -s" from an admin prompt and tell me if you have any values for Microsoft.Azure.Management.ResourceManager present in the output?

Grant-Rc commented 2 years ago

sure @stuartko

image

stuartko commented 1 year ago

@Grant-Rc StrongName verification bypass is added for the binary. Is this machine joined to a domain? It's possible group policy is restricting the ability to disable strong name verification. This shouldn't require a reboot, but I'm presuming you're seeing the same failure even after rebooting after adding the registry key?

Eventually this won't be an issue in Public Preview because we'll sign all of our bits. I'm not aware of any Powershell specific policies for strong name verification, but they could also be buried in group policy or managed device policies. Were you able to install the AZ CLI preview client? If so, this narrows it down to being Powershell specific (meaning it's a non-standard policy/config set on your client somewhere within Powershell).

harshpatel17 commented 1 year ago

Hi team, just to add - I'm having the same issue in both PowerShell and CLI as reported by @Grant-Rc above. Tested on two different machines, one of which was new and clean windows VM.

@jonclyde Before passing of a new build I wanted to confirm if you were able to do a couple of things

Open powershell as admin Run the following command & "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe" -m pip install -e path of unzipped sdk --force-reinstall

That error usually come from the CLI not being mapped to the SDK, the above command should fix that issue