不工作Swagger Ui
500:{“消息”:“发生错误。”,“ExceptionMessage”:“DynamicMethod的类型所有者无效。”,“ExceptionType”:“System.ArgumentException”,“StackTrace”:“在System.Reflection.Emit。 DynamicMethod.Init(String name,MethodAttributes属性,CallingConventions callingConvention,Type returnType,Type []签名,Type owner,Module m,Boolean skipVisibility,Boolean transparentMethod,StackCrawlMark&stackMark)\ r \ n在System.Reflection.Emit.DynamicMethod .. ctor(String name,Type returnType,Type [] parameterTypes,Type owner,Boolean skipVisibility)\ r \ n at Newtonsoft.Json.Utilities.DynamicReflectionDelegateFactory.CreateDynamicMethod(String name,Type returnType,Type [] parameterTypes,Type owner)\ r \ n \ n at Newtonsoft.Json.Utilities.DynamicReflectionDelegateFactory.CreateDefaultConstructor [T](Type type)\ r \ n在Newtonsoft.Json.Serialization.DefaultContractResolver.GetDefaultCreator(Type createdType)\ r \ n在Newtonsoft.Json.Serialization.DefaultContractResolver。 InitializeContract(JsonContr合作)\ r \ n at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateArrayContract(Type objectType)\ r \ n在Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract(Type objectType)\ r \ n在Newtonsoft.Json.Serialization。在Swashbuckle.Swagger.SchemaRegistry.CreateInlineSchema(类型类型)\ r \ n的Swashbuckle.Swagger.SchemaRegistry.GetOrRegister(类型类型)\ r \ n的Swashbuckle.Swagger.SwaggerGenerator中的DefaultContractResolver.ResolveContract(Type type)\ r \ n。在Swashbuckle.Swagger.SwaggerGenerator中创建参数(字符串位置,ApiParameterDescription paramDesc,SchemaRegistry schemaRegistry)\ r \ n。<> c__DisplayClass12.b__11(ApiParameterDescription paramDesc)\ r \ n在System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext()\r\n at System.Collections.Generic.List
1..ctor(IEnumerable1 collection)\r\n at System.Linq.Enumerable.ToList[TSource](IEnumerable
1 source) \ r \ n在Swashbuckle.Swagger.SwaggerGenerator.CreateOperation(ApiDescription apiDesc,SchemaRegistry schemaRegistry)\ r \ n at Swashbuckle.Swagger.SwaggerGenerator.CreatePathItem(IEnumerable1 apiDescriptions, SchemaRegistry schemaRegistry)\r\n at Swashbuckle.Swagger.SwaggerGenerator.<>c__DisplayClass7.<GetSwagger>b__4(IGrouping
2 group)\ r \ n at Syst em.Linq.Enumerable.ToDictionary [TSource,TKey,TElement](IEnumerable1 source, Func
2 keySelector,Func2 elementSelector, IEqualityComparer
1 comparer)\ r \ n在Swashbuckle.Swagger.SwaggerGenerator.GetSwagger(String rootUrl,String apiVersion)\ r \ n在Swashbuckle.Application.SwaggerDocsHandler .SendAsync(HttpRequestMessage请求,CancellationToken cancellationToken)\ r \ n在System.Net.HttpMessageInvoker.SendAsync(HttpRequestMessage请求,CancellationToken cancellationToken)\ r \ n在System.Web.Http.Dispatcher.HttpRoutingDispatcher.SendAsync(HttpRequestMessage请求, CancellationToken cancellationToken)\ r \ n在System.Net.Http.DelegatingHandler.SendAsync(HttpRequestMessage请求,CancellationToken cancellationToken)\ r \ n在System.Web.Http.HttpServer.d__0.MoveNext()“} http://localhost:5352/swagger/docs/v1
当我收到此错误时,是因为我的ResponseType定义(WebApi)中有错误/遗漏。编译器很好用,但Swagger没有。
失败
[ResponseType(typeof(IEnumerable<>))]
工作
[ResponseType(typeof(IEnumerable<string>))]
我有所有控制器的基类,这是一个问题。
我修复了这个解决方案。
[ApiExplorerSettings(IgnoreApi = true)]解决了我的问题,谢谢。对于可能需要此功能的任何其他人而言,请注意。如果你把它放在基本控制器本身上它将隐藏所有子控制器(不好),但是如果你把它放在属性/方法本身它将正确显示孩子。