我正在尝试用 C# 编写 PowerShellCmdlet。它是一个用于进行 REST API 调用的 PowerShell 命令。这是代码重要功能的片段 -
[Cmdlet(VerbsCommon.Get, "MXL3Firewall")]
[OutputType(typeof(MXFirewallRule))]
public class GetMXL3FirewallCommand : PSCmdlet
{
[Parameter(
Mandatory = true,
Position = 0,
ValueFromPipeline = true,
ValueFromPipelineByPropertyName = true)]
public string Token { get; set; }
[Parameter(
Mandatory = true,
Position = 1,
ValueFromPipeline = true,
ValueFromPipelineByPropertyName = true)]
public string NetId { get; set; }
private static async Task<IList<MXFirewallRule>> GetFWRules(string Token, string NetId)
{
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Add("X-Cisco-Meraki-API-Key", Token);
// Created the request header above
var streamTask = client.GetStreamAsync($"https://api.meraki.com/api/v0/networks/{NetId}/l3FirewallRules");
// converting the serialized JSON response into a C# object
return await JsonSerializer.DeserializeAsync<IList<MXFirewallRule>>(await streamTask);
}
}
private static IList<MXFirewallRule> ProcessRecordAsync(string Token, string NetId)
{
var task = GetFWRules(Token, NetId);
task.Wait();
return task.Result;
}
protected override void ProcessRecord()
{
WriteVerbose("Entering Get Firewall Rules Call");
var list = ProcessRecordAsync(Token, NetId);
WriteObject(list, true);
}
}
我收到以下错误 -
Get-MXL3Firewall : Could not load file or assembly 'System.Threading.Tasks.Extensions, Version=4.2.0.1,
Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file
specified.
At line:1 char:1
+ Get-MXL3Firewall -Token $token -NetId $netid
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-MXL3Firewall], FileNotFoundException
+ FullyQualifiedErrorId : System.IO.FileNotFoundException,RestToPSCommand.GetMXL3FirewallCommand
在(.csproj)中我有以下行 -
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
我尝试按照所述更新 Nuget 包 here ,但这并没有帮助。 我该如何修复这个错误?
最佳答案
有可能发生的情况是其他一些引用正在尝试访问版本 4.2.0.1。 System.Threading.Tasks.Extensions 的。这被称为 DLL Hell,通常很难修复。如果是这种情况,您将必须查看引用并尝试找出哪个引用引用了 System.Threading.Tasks.Extensions 版本 4.2.0.1。
您可以尝试更新您的 NuGet 包。或许可以解决问题。
祝你好运!!!
关于c# - 无法加载文件或程序集“System.Threading.Tasks.Extensions,版本=4.2.0.1”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65563556/