小编Kev*_*ith的帖子

由Microsoft.NET.Sdk.Functions引起的版本冲突

我有一个项目引用2个软件包的问题,​​然后引用Newtonsoft.Json,但两个版本都不同.我使用的NuGet包RefitMicrosoft.NET.Sdk.Functions.当我尝试构建解决方案时,我收到以下错误:

C:\dev\noddy\noddy-api\src\noddy.Api>dotnet build
C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj : error NU1607: Version conflict detected for Newtonsoft.Json. Reference the package directly from the project to resolve this issue. \r
C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj : error NU1607:  noddy.Api (>= 1.0.0) -> Refit (>= 4.0.1) -> Newtonsoft.Json (>= 10.0.3) \r
C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj : error NU1607:  noddy.Api (>= 1.0.0) -> Microsoft.NET.Sdk.Functions (>= 1.0.2) -> Newtonsoft.Json (>= 9.0.1).
Run Code Online (Sandbox Code Playgroud)

现在,如果我按照它说的做,并直接从我的项目引用包,我在构建时会遇到另一个错误:

C:\dev\noddy\noddy-api\src\noddy.Api>dotnet add package Newtonsoft.Json
  Writing C:\Users\joebloggs\AppData\Local\Temp\tmp7250.tmp
info : Adding PackageReference for package 'Newtonsoft.Json' into project 'C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj'.
log  : Restoring packages …
Run Code Online (Sandbox Code Playgroud)

c# msbuild azure azure-functions

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

如何在asp.net core 3.1中将body中的null传递给端点

我在 asp.net core 3.1 控制器中有以下操作

[ApiController]
[Route("example")]
public class MyExampleController : ControllerBase
{
    [HttpPost("{id}/value")]
    public async Task<IActionResult> Post(string id, [FromBody] int? value)
      => Task.FromResult(Ok());
}
Run Code Online (Sandbox Code Playgroud)

这工作得很好,如果我发布为int的身体值(例如:12,等...)

但是,我找不到null传入值的方法。

如果我传入一个空的正文或null正文,我会得到 400 的状态代码,并带有返回的验证消息A non-empty request body is required.

我还尝试将value参数更改为可选参数,默认值为null

public async Task<IActionResult> Post(string id, [FromBody] int? value = null)
Run Code Online (Sandbox Code Playgroud)

如何将 null 传递给此操作?

c# asp.net-core asp.net-core-3.1

9
推荐指数
2
解决办法
5841
查看次数

C#Interactive - 无法加载文件或程序集

我正在尝试使用C#Interactive试用一些mongodb驱动程序,但是一旦我尝试创建一个MongoClient我得到以下异常:

> var client = new MongoClient();
Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
  + MongoDB.Driver.Core.Connections.ClientDocumentHelper.CreateOSDocument()
  + Lazy<T>.CreateValue()
  + Lazy<T>.get_Value()
  + MongoDB.Driver.Core.Connections.ClientDocumentHelper.CreateClientDocument(string)
  + MongoDB.Driver.Core.Connections.BinaryConnectionFactory..ctor(MongoDB.Driver.Core.Configuration.ConnectionSettings, MongoDB.Driver.Core.Connections.IStreamFactory, MongoDB.Driver.Core.Events.IEventSubscriber)
  + MongoDB.Driver.Core.Configuration.ClusterBuilder.BuildCluster()
  + MongoDB.Driver.ClusterRegistry.CreateCluster(MongoDB.Driver.ClusterKey)
  + MongoDB.Driver.ClusterRegistry.GetOrCreateCluster(MongoDB.Driver.ClusterKey)
  + MongoDB.Driver.MongoClient..ctor(MongoDB.Driver.MongoClientSettings)
  + MongoDB.Driver.MongoClient..ctor()
Run Code Online (Sandbox Code Playgroud)

以下是重现的全部细节: -

通过命令行安装最新版本的MongoDB驱动程序.

C:\dev>nuget.exe install MongoDB.Driver -OutputDirectory tools -ExcludeVersion

Feeds used:
  https://api.nuget.org/v3/index.json
  C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
  C:\Program Files\Microsoft SDKs\Service Fabric\packages\

Attempting to gather dependencies information for package …
Run Code Online (Sandbox Code Playgroud)

c# mongodb c#-interactive

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

Lambda函数处理程序C#中的取消令牌

C#中的AWS Lambda函数处理程序是否提供取消令牌?

我已经阅读了AWS网站上的文档(https://docs.aws.amazon.com/lambda/latest/dg/dotnet-programming-model-handler-types.html),但在任何提及取消的地方都看不到令牌。我还检查了ILambdaContext传递给执行方法的,但是那里什么也没有。

我以前使用过Azure Functions,它们只是将它作为本文所述的函数的另一个参数传递给了我:https : //docs.microsoft.com/zh-cn/azure/azure-functions/functions-dotnet-类别库#取消令牌

c# amazon-web-services cancellation-token aws-lambda

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

将枚举与自定义Fluent断言等效步骤进行比较

我正在尝试编写一个自定义的Fluent断言等效步骤,以将Enum主题侧的值与异常侧的字符串进行比较。

我似乎要面对的问题是,传递给的主题类型在调用IEquivalencyStepmy之前已经转换为字符串EquivalencyStep

流畅的断言中是否发生了一些魔术,试图将枚举直接转换为字符串?

代码示例如下:

public class SubjectClass
{
    public EnumType Prop1 { get; set; }
}

public enum EnumType
{
    A,
    B,
    C
}

public class ExpectionClass
{
    public string Prop1 { get; set; }
}

[TestFixture]
public class ComparingEnumWithTests
{
    [Test]
    public void Test()
    {
        var expection = new ExpectionClass() {Prop1 = "bbb"};

        var subject = new SubjectClass() {Prop1 = EnumType.B};

        subject.ShouldBeEquivalentTo(expection, opt => opt.Using(new ComparingEnumWith<EnumType>(new Dictionary<string, EnumType>()
        {
            {"aaa", EnumType.A },
            {"bbb", …
Run Code Online (Sandbox Code Playgroud)

.net c# fluent-assertions

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

如何在本地运行Service Fabric exe

我该如何运行仅通过执行*.exe文件在本地运行的,在服务结构运行时之上构建的服务?

当前,它仅引发异常,然后终止应用程序。

我希望能够隔离启动服务,以便在创建服务包之前将其端对端测试,然后再将其部署为应用程序的一部分。之前,我已经使用TopShelf和Web Jobs进行了此操作,但这似乎不适用于Service Fabric,即使它只是基于控制台应用程序构建的。

c# console-application azure-service-fabric

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

清除 nuget 缓存后拒绝访问路径“InterfaceStubGenerator.BuildTasks.dll”

我刚刚使用以下方法清除了所有 nuget 缓存:

dotnet nuget locals all --clear
Run Code Online (Sandbox Code Playgroud)

但是现在当我尝试恢复/构建时出现以下错误

C:\dev\noddy\src\noddy.Api>dotnet build
C:\Program Files\dotnet\sdk\2.0.0\NuGet.targets(102,5): error : Access to the path 'InterfaceStubGenerator.BuildTasks.dll' is denied. [C:\dev\noddy\src\noddy.Api\noddy.Api.csproj]
Run Code Online (Sandbox Code Playgroud)

有人知道怎么修这个东西吗?

nuget dotnet-cli

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

为什么我需要将 XmlWriterSettings.Async 设置为 true 才能使用异步方法?

我上次使用已经有一段时间了,XmlWriter但因为今天是编写一些 XML 的幸运日,所以我开始...Async默认使用所有方法,但立即出现以下异常:

System.InvalidOperationException :如果要使用异步方法,请将 XmlWriterSettings.Async 设置为 true。

我必须在传递给构造函数的设置对象上设置一个标志,这对我来说似乎有点奇怪,XmlWriter以便我可以在类上打开方法的使用。

例如:

using (var xmlWriter = XmlWriter.Create(stringBuilder))
{
    await xmlWriter.WriteStartElementAsync("", "root", "")
        .ConfigureAwait(false);
}
Run Code Online (Sandbox Code Playgroud)

但是会抛出异常:

using (var xmlWriter = XmlWriter.Create(stringBuilder, new XmlWriterSettings(){Async = true}))
{
    await xmlWriter.WriteStartElementAsync("", "root", "")
        .ConfigureAwait(false);
}
Run Code Online (Sandbox Code Playgroud)

会工作得很好。

有谁知道这背后的原因?

c# xmlwriter async-await

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

在 PowerShell 中执行 `where.exe`

我想要 PowerShell 中提供给我的相同功能where.exe

我试图找到可执行标准的 cmdlet 替代品,但找不到任何东西。

因此,默认情况下,我尝试在 PowerShell 中执行 where 命令,但有一个别名映射到该命令。

PS C:\> Get-Command 其中

命令类型名称 版本 源
----------- ---- ------- ------
别名 where ->Where-Object

有没有办法在 PowerShell 中执行where或者有更好的方法来达到相同的结果?

powershell

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

是否可以对 dotnet 全局/本地工具使用通配符版本?

我们使用正常方式dotnet-tools.json为我们的项目设置 dotnet 本地工具,但想知道是否有一种方法可以使用通配符版本作为版本号,就像您在 csprojs 中使用包引用所做的那样?

<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.0-rc.1.*" />
Run Code Online (Sandbox Code Playgroud)

我尝试将其更改dotnet-tools.json为以下内容:

{
  "version": 1,
  "isRoot": true,
  "tools": {
    "dotnet-ef": {
      "version": "5.0.0-rc.1.*",
      "commands": [
        "dotnet-ef"
      ]
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

但是运行却dotnet tool restore出现以下错误

Invalid manifest file. Path C:\dev\x\x.api\.config\dotnet-tools.json:
        In package dotnet-ef:
                Version 5.0.0-rc.1.* is invalid.
Run Code Online (Sandbox Code Playgroud)

.net .net-core dotnet-tool

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