执行Import-Module Az.Storage时加载Azure.Storage.Queues程序集失败
问题描述
执行Import-Module Az.Storage时出现以下报错:
PS error: System.Management.Automation.CommandNotFoundException: The 'New-AzStorageAccount' command was found in the module 'Az.Storage', but the module could not be loaded due to the following error: [Could not load file or assembly 'Azure.Storage.Queues, Version=12.12.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8'.]
For more information, run 'Import-Module Az.Storage'.
---> System.Management.Automation.CmdletInvocationException: Could not load file or assembly 'Azure.Storage.Queues, Version=12.12.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8'.
---> System.IO.FileLoadException: Could not load file or assembly 'Azure.Storage.Queues, Version=12.12.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8'.
at System.Management.Automation.Runspaces.InitialSessionState.Bind_LoadAssemblies(ExecutionContext context)
at System.Management.Automation.Runspaces.InitialSessionState.Bind(ExecutionContext context, Boolean updateOnly, PSModuleInfo module, Boolean noClobber, Boolean local, Boolean setLocation)
at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModuleManifest(String moduleManifestPath, ExternalScriptInfo manifestScriptInfo, Hashtable data, Hashtable localizedData, ManifestProcessingFlags manifestProcessingFlags, Version minimumVersion, Version maximumVersion, Version requiredVersion, Nullable`1 requiredModuleGuid, ImportModuleOptions& options, Boolean& containedErrors)
--- End of inner exception stack trace ---
解决步骤
强制重新安装Az.Storage模块
打开管理员权限的PowerShell,执行以下命令彻底移除旧版本并重新安装:Uninstall-Module Az.Storage -Force -AllVersions Install-Module Az.Storage -Force -AllowClobber该操作会确保下载完整的模块包,修复缺失的依赖程序集。
更新全套Az模块
单个模块依赖缺失可能源于Az套件版本不兼容,执行以下命令更新所有Az模块:Update-Module Az -Force -AllowClobber手动检查并修复程序集
找到Az.Storage模块的安装路径(通常为C:\Program Files\WindowsPowerShell\Modules\Az.Storage\<对应版本号>),确认是否存在Azure.Storage.Queues.dll文件。若缺失,可从同版本Az模块的其他依赖目录复制对应版本的文件,或手动下载匹配版本的程序集放入该目录。验证PowerShell执行策略
确保PowerShell允许加载模块,执行命令查看当前策略:Get-ExecutionPolicy若结果不是
RemoteSigned或Unrestricted,执行以下命令调整:Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
内容的提问来源于stack exchange,提问作者Node.JS

