小编Ria*_*son的帖子

获取 ArgumentException:升级到 .NET Core 2.2 后,使用 ActionResult<JsonResult>> 作为返回类型的类型参数无效

当我尝试访问任何像下面所示的代码那样构建的 API 端点时,我收到以下运行时错误:

ArgumentException: Invalid type parameter 
'Microsoft.AspNetCore.Mvc.JsonResult' specified for 'ActionResult<T>'.
Run Code Online (Sandbox Code Playgroud)

错误

此代码在 .NET Core 2.1 中的应用程序中按预期运行。升级到 .NET Core 2.2 后,这个问题就被打破了。

这是控制器中我的一个端点的代码。

    [HttpGet]
    public async Task<ActionResult<JsonResult>> Get()
    {
        try
        {
            MongoConnector mongo = new 
            MongoConnector(_configService.GetMongoConnectionString());

            List<BsonDocument> queues = await mongo.AggregateQueues(
                (aggregator) => aggregator
                                .Match(CommonAggregation.SinceYesterday)
                                .Sort(CommonAggregation.SortByDate)
                                .Group(QueueAggregators.GroupQueuesByMessagingName)
            );


            List<QueueHealth> queueHealth = await MongoConnector.DeserializeList<QueueHealth>(queues);
            JsonResult result = new JsonResult(queueHealth);
            result.Value = queueHealth;
            result.ContentType = "application/json";
            result.StatusCode = 200;

            return result;

        }
        catch (Exception ex)
        {
            logger.Error(ex, "An exception was thrown within /api/MessageQueue");

            return …
Run Code Online (Sandbox Code Playgroud)

c# api json .net-core .net-core-2.2

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

Python使用in而不是in中删除字符串中的重复项

我正在尝试使用in和not in运算符以及Accumulator Pattern来删除字符串中的所有重复字母,并在保持顺序的同时返回一个新字符串.

withDups = "The Quick Brown Fox Jumped Over The Lazy Dog"

def removeDups(s):
    alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
    sWithoutDups = ""
    for eachChar in withDups:
        if eachChar in alphabet:
            sWithoutDups = eachChar + sWithoutDups
        return sWithoutDups

print(removeDups(withDups))
Run Code Online (Sandbox Code Playgroud)

我当前的代码只返回字符串的第一个字母.我对python和编码一般都是新手,所以请原谅我是否忽略了一些简单的东西,我现在的代码甚至不是正确的方向,或者我发布了一些不应该发布的东西.

python string accumulator

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

标签 统计

.net-core ×1

.net-core-2.2 ×1

accumulator ×1

api ×1

c# ×1

json ×1

python ×1

string ×1