小编Grz*_*lko的帖子

JoinableTaskFactory.RunAsync 的正确用法是什么?

我在网上搜索,但有关的信息很少 ThreadHelper.JoinableTaskFactory.RunAsync

如果我有以下代码,请Test1运行MainThread

public bool Test1()
{
    // Do something here
    ThreadHelper.JoinableTaskFactory.RunAsync(this.Test2);
    // Do something else
    return false;
}

private async Task Test2()
{
    await TaskScheduler.Default;
    // do something here    
    await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
    // do something here
}
Run Code Online (Sandbox Code Playgroud)

如果RunAsync从未等待过可以吗?如果Test1Test2运行完成之前返回会发生什么?

c# multithreading asynchronous

8
推荐指数
1
解决办法
3751
查看次数

如何在 ASP.NET Core 3.1 中实现自定义 ValidateAntiforgeryTokenAuthorizationFilter

我想实现一个过滤器,在使用身份验证令牌身份验证 ( Bearer)时跳过防伪令牌的验证。

在 ASP.NET Core 2.2 中,ValidateAntiforgeryTokenAuthorizationFilterAutoValidateAntiforgeryTokenAuthorizationFilter是公共的(即使位于Microsoft.AspNetCore.Mvc.ViewFeatures.Internal命名空间中),所以我能够从后者继承并ShouldValidate轻松覆盖该方法。

在 ASP.NET Core 3.0 中,它们变成了内部的,因此不可能只从它们继承。我可以复制粘贴代码,但这显然不是理想的解决方案。

MSDN 的ASP.NET Core文章中关注了防止跨站点请求伪造 (XSRF/CSRF) 攻击,但它并没有真正提到与我的场景相关的任何内容。

csrf antiforgerytoken asp.net-core asp.net-core-webapi

6
推荐指数
1
解决办法
2792
查看次数

Azure 策略创建一个deployifnotexists 策略

DeployIfNotExists我正在尝试根据现有策略创建策略AuditIfNotExists。部署时不会出错,但会错误提示“没有相关资源与策略定义中的效果详细信息匹配”。当评估政策时。AuditIfnotExists当我将其部署到同一管理组时,该策略确实运行良好。我想知道我是否错过了什么。

此策略用于创建删除 NSG 组(如果不存在)的警报。这是DeployIfNotExists政策 - 你们觉得有什么问题吗?任何意见表示赞赏。谢谢。

{
  "$schema":"https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion":"1.0.0.0",
  "parameters":{
    "effect":{
      "type":"string",
      "metadata":{
        "displayName":"Effect",
        "description":"Enable or disable the execution of the policy"
      },
      "allowedValues":[
        "AuditIfNotExists",
        "deployIfNotExists",
        "Disabled"
      ],
      "defaultValue":"deployIfNotExists"
    }
  },
  "variables":{
    "actionGroupName":"dsactiongroup"
  },
  "resources":[
    {
      "name":"CIS5.2.3-EnsureAuditDeleteNSG",
      "type":"Microsoft.Authorization/policyDefinitions",
      "apiVersion":"2019-09-01",
      "properties":{
        "policyType":"Custom",
        "displayName":"CIS 5.2.3 Ensure that Activity Log Alert exists for Delete Network Security Group (Scored)",
        "description":"Monitor Activity Alerts exist for specific activities.",
        "mode":"all",
        "metadata":{
          "category":"Audit"
        },
        "parameters":{
          
        },
        "policyRule":{
          "if":{
            "allOf":[
              {
                "field":"type", …
Run Code Online (Sandbox Code Playgroud)

azure azure-policy

6
推荐指数
1
解决办法
4112
查看次数

如何将带有附加属性的 PSCustomObject 转换为自定义类

有没有一种巧妙的方法可以将 a 转换PSCustomObject为自定义类作为 PowerShell 5.1 中的函数参数?自定义对象包含附加属性。

我希望能够做这样的事情:

class MyClass {
    [ValidateNotNullOrEmpty()][string]$PropA
}

$input = [pscustomobject]@{
    PropA          = 'propA';
    AdditionalProp = 'additionalProp';
}

function DuckTypingFtw {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory = $True, Position = 0, ValueFromPipeline)] [MyClass] $myObj
    )
    'Success!'
}

DuckTypingFtw $input

Run Code Online (Sandbox Code Playgroud)

不幸的是Success!,我得到的不是:

DuckTypingFtw:无法处理参数“myObj”的参数转换。无法将值“@{PropA=propA;AdditionalProp=additionalProp}”转换为类型“MyClass”。错误:“无法转换”@{PropA=propA; “AdditionalProp=additionalProp}”
类型“System.Management.Automation.PSCustomObject”的值要键入“MyClass”。在 C:\temp\tmp.ps1:23 字符:15 + DuckTypingFtw $input + ~~~~~~ + CategoryInfo : InvalidData: (:) [DuckTypingFtw], ParameterBindingArgumentTransformationException + ExcellentQualifiedErrorId : ParameterArgumentTransformationError,DuckTypingFtw

如果我注释掉AdditionalProp,一切正常。

基本上,我想要实现的目标是从一个函数返回一个对象并将其传递给第二个函数,同时确保第二个函数的参数具有所有预期的属性。

powershell pscustomobject powershell-5.0

5
推荐指数
1
解决办法
1747
查看次数

在未安装完整 SDK 的情况下运行 dotnet 测试

我想在构建服务器上运行一些 nUnit 测试,而不必在那里安装 .NET Core SDK。

测试目标netcoreapp3.1.

对于 .NET Framework 可以使用 运行它们nunit-console-runner,但对于 .NET Core 似乎不可能 - 请参阅/sf/answers/3699839391/

如果发现这个问题https://github.com/Microsoft/vstest/issues/1224,但它似乎没有提供任何合理的解决方案。

类似问题:在没有安装 SDK 的情况下运行 xUnit 测试

.net nunit nunit-console .net-core dotnet-test

5
推荐指数
0
解决办法
1643
查看次数

VirtualBox 6.1.28 无法在 Windows 上加载 R0 模块(`VERR_LDR_GENERAL_FAILURE`)

VirtualBox 6.1.28 无法在 Windows 上启动盒子,并出现以下错误:

Failed to load R0 module C:\Program Files\Oracle\VirtualBox/VMMR0.r0:
SUP_IOCTL_LDR_OPEN failed (VERR_LDR_GENERAL_FAILURE).
Failed to load VMMR0.r0 (VERR_LDR_GENERAL_FAILURE).
Run Code Online (Sandbox Code Playgroud)

virtualbox vagrant

5
推荐指数
1
解决办法
2万
查看次数