小编Sil*_*res的帖子

尝试使用 .Net Core 3.0 (MongoDB.Driver 2.8.0) 获取对 MongoDB 集合的引用时出现异常

我的环境:

Microsoft.NETCore.Platforms (3.0.0-preview5.19224.8)

MongoDB.Driver (2.8.0)

在此处输入图片说明

我的问题:

在更新“Microsoft.NETCore.Platforms”版本之前,以下代码运行良好:

//Collection of resales
public IMongoCollection<Revenda> CollRevendas;

public BaseRepository(IConfiguration config)
{
    try
    {
        // Location of the database, configured in the "appsettings.json" file
        var client = new MongoClient(config.GetConnectionString("Config.api.mstiDFE"));

        // Name of the database
        Database = client.GetDatabase("api_mstiDFE_II");

        // Get the reference for the collection "Resales"
        CollRevendas = Database.GetCollection<Revenda>("Revendas");

    }
    catch (System.Exception ex)
    {
        throw;
    }

}
Run Code Online (Sandbox Code Playgroud)

更新后,当尝试执行“ColRevendas = Database.GetCollection("Revendas");” 语句,抛出以下异常:

{“'MongoDB.Bson.Serialization.BsonClassMap' 的类型初始值设定项引发异常。”}

在此处输入图片说明

使用以下堆栈跟踪:

System.TypeInitializationException: The type initializer for 'MongoDB.Bson.Serialization.BsonClassMap' threw an exception. ---> System.ArgumentNullException: Value …
Run Code Online (Sandbox Code Playgroud)

c# mongodb .net-core

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

如何在 NSwag 生成的文档中启用“text/plain”内容类型?

我正在尝试在 AspNetCore 3.1 API 中创建一个控制器。c#,借助“NSwag.AspNetCore”13.1.3。该控制器的目的是接收并返回纯文本(不是 json)。

\n\n

控制器代码如下所示:

\n\n
[HttpPost]\n[Route("api/BodyTypes/JsonPlainBody")]\n[Consumes("text/plain")]    \n[Produces("text/plain")]\npublic string PlainStringBody([FromBody] string content)\n{\n    return content;\n}   \n
Run Code Online (Sandbox Code Playgroud)\n\n

摘自描述此服务的“swagger.json”文件:

\n\n
...\n"/api/BodyTypes/JsonPlainBody": {\n  "post": {\n    "tags": [\n      "Acess\xc3\xb3rios - Opera\xc3\xa7\xc3\xb5es diversas"\n    ],\n    "operationId": "Acessorios_PlainStringBody",\n    "requestBody": {\n      "x-name": "content",\n      "content": {\n        "application/json": {\n          "schema": {\n            "type": "string"\n          }\n        }\n      },\n      "required": true,\n      "x-position": 1\n    },\n    "responses": {\n      "200": {\n        "description": "",\n        "content": {\n          "application/json": {\n            "schema": {\n              "type": "string"\n            }\n          }\n        }\n      }\n    }\n  }\n}\n...\n
Run Code Online (Sandbox Code Playgroud)\n\n

SwaggerUI 中该控制器的表示不允许我选择内容类型“text/plain”,因此会生成错误格式的 http 请求,导致服务器返回与数据格式相关的错误(415 - …

c# swagger asp.net-core nswag

7
推荐指数
0
解决办法
4588
查看次数

标签 统计

c# ×2

.net-core ×1

asp.net-core ×1

mongodb ×1

nswag ×1

swagger ×1