我的环境:
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) 我正在尝试在 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} \nRun 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...\nRun Code Online (Sandbox Code Playgroud)\n\nSwaggerUI 中该控制器的表示不允许我选择内容类型“text/plain”,因此会生成错误格式的 http 请求,导致服务器返回与数据格式相关的错误(415 - …