zoukankan      html  css  js  c++  java
  • 【NSwag】System.InvalidOperationException错误

    原地址

    https://github.com/RicoSuter/NSwag/issues/3584

    环境

    ASP.NETCore:3.1

    NSwag.AspNetCore:13.13.0

    引发错误

    System.InvalidOperationException: Method may only be called on a Type for which Type.IsGenericParameter is true.
       at System.RuntimeType.get_GenericParameterPosition()
       at Namotion.Reflection.ContextualType.<get_Properties>b__42_0(PropertyInfo property)
       at System.Linq.Enumerable.SelectArrayIterator`2.ToArray()
       at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
       at Namotion.Reflection.ContextualType.get_Properties()
       at Namotion.Reflection.ContextualTypeExtensions.GetContextualProperties(Type type)
       at NJsonSchema.Generation.JsonSchemaGenerator.ApplyAdditionalProperties[TSchemaType](TSchemaType schema, Type type, JsonSchemaResolver schemaResolver)
       at NJsonSchema.Generation.JsonSchemaGenerator.GenerateObject(JsonSchema schema, JsonTypeDescription typeDescription, JsonSchemaResolver schemaResolver)
       at NSwag.Generation.OpenApiSchemaGenerator.GenerateObject(JsonSchema schema, JsonTypeDescription typeDescription, JsonSchemaResolver schemaResolver)
       at NJsonSchema.Generation.JsonSchemaGenerator.Generate[TSchemaType](TSchemaType schema, ContextualType contextualType, JsonSchemaResolver schemaResolver)
       at NJsonSchema.Generation.JsonSchemaGenerator.Generate[TSchemaType](ContextualType contextualType, JsonSchemaResolver schemaResolver)
       at NJsonSchema.Generation.JsonSchemaGenerator.GenerateWithReferenceAndNullability[TSchemaType](ContextualType contextualType, Boolean isNullable, JsonSchemaResolver schemaResolver, Action`2 transformation)
       at NSwag.Generation.OpenApiSchemaGenerator.GenerateWithReferenceAndNullability[TSchemaType](ContextualType contextualType, Boolean isNullable, JsonSchemaResolver schemaResolver, Action`2 transformation)
       at NSwag.Generation.AspNetCore.Processors.OperationResponseProcessor.Process(OperationProcessorContext operationProcessorContext)
       at NSwag.Generation.AspNetCore.AspNetCoreOpenApiDocumentGenerator.RunOperationProcessors(OpenApiDocument document, ApiDescription apiDescription, Type controllerType, MethodInfo methodInfo, OpenApiOperationDescription operationDescription, List`1 allOperations, OpenApiDocumentGenerator swaggerGenerator, OpenApiSchemaResolver schemaResolver)
       at NSwag.Generation.AspNetCore.AspNetCoreOpenApiDocumentGenerator.AddOperationDescriptionsToDocument(OpenApiDocument document, Type controllerType, List`1 operations, OpenApiDocumentGenerator swaggerGenerator, OpenApiSchemaResolver schemaResolver)
       at NSwag.Generation.AspNetCore.AspNetCoreOpenApiDocumentGenerator.GenerateForControllers(OpenApiDocument document, IGrouping`2[] apiGroups, OpenApiSchemaResolver schemaResolver)
       at NSwag.Generation.AspNetCore.AspNetCoreOpenApiDocumentGenerator.GenerateAsync(ApiDescriptionGroupCollection apiDescriptionGroups)
       at NSwag.AspNetCore.Middlewares.OpenApiDocumentMiddleware.GenerateDocumentAsync(HttpContext context)
       at NSwag.AspNetCore.Middlewares.OpenApiDocumentMiddleware.GetDocumentAsync(HttpContext context)
       at NSwag.AspNetCore.Middlewares.OpenApiDocumentMiddleware.Invoke(HttpContext context)
       at NSwag.AspNetCore.Middlewares.SwaggerUiIndexMiddleware.Invoke(HttpContext context)
       at NSwag.AspNetCore.Middlewares.RedirectToIndexMiddleware.Invoke(HttpContext context)
       at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

    处理方案

    将NSwag.AspNetCore类库升级v13.13.1

    问题描述

    修改前

    <PackageReference Include="NSwag.AspNetCore" Version="13.13.0" />

    发布后无法打开,而且本地打开也报错

    (1)注释了所有的Controller下面的方法

    然后Swagger页面可以打开了,只是页面没有可用的接口

     (2)结合报错提示Type,想到了MessageModel类有个泛型的T Data属性,随记更换了返回值

    现在Swagger也运行正常,而且展示把Action也展示出来了

     (3)确定了是由于MessageModel泛型引发了异常,但是具体的细节就没有去看了

    修改后

    <PackageReference Include="NSwag.AspNetCore" Version="13.13.1" />

    仍然是返回MessageModel,运行正常,所以还是NSwag类库的问题

  • 相关阅读:
    实验四 交换机的Telnet远程登陆配置
    实验三 交换机的基本配置与管理
    实验二 认识Packet Tracer软件
    实验一 网络连接线的制作
    python入门(七)
    python入门(六)
    python入门(五)
    Android练习(二)
    Android练习(一)
    python入门(四)
  • 原文地址:https://www.cnblogs.com/masonblog/p/15622930.html
Copyright © 2011-2022 走看看