昂首阔步不工作有什么建议吗?

时间:2019-04-22 11:56:57

标签: swagger swagger-ui

无法使用Swagger Ui

500:{“ Message”:“发生错误。”,“ ExceptionMessage”:“ DynamicMethod的无效类型所有者。”,“ ExceptionType”:“ System.ArgumentException”,“ StackTrace”:“位于System.Reflection .Emit.DynamicMethod.Init(字符串名称,MethodAttributes属性,CallingConventions,CallingConvention,Type returnType,Type []签名,类型所有者,模块m,布尔型skipVisibility,布尔型transparentMethod,StackCrawlMark和stackMark)\ r \ n位于System.Reflection.Emit。 DynamicMethod..ctor(字符串名称,类型returnType,类型[] parameterTypes,类型所有者,布尔skipVisibility)\ r \ n在Newtonsoft.Json.Utilities.DynamicReflectionDelegateFactory.CreateDynamicMethod(字符串名称,类型returnType,类型[] parameterTypes,类型所有者)\ r \ n在Newtonsoft.Json.Utilities.DynamicReflectionDelegateFactory.CreateDefaultConstructor [T](Type type)\ r \ n在Newtonsoft.Json.Serialization.DefaultContractResolver.GetDefaultCreator(Type createdType)\ r \ n在Newtonsoft.Json.Serialization .DefaultContractResolver.InitializeContract(JsonCo 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(Type type)\ r \ n在Swashbuckle.Swagger.SchemaRegistry.GetOrRegister(Type type)\ r \ n在Swashbuckle.Swagger.SwaggerGenerator处为DefaultContractResolver.ResolveContract(Type type)\ r \ n。 CreateParameter(String location,ApiParameterDescription paramDesc,SchemaRegistry schemaRegistry)\ r \ n在Swashbuckle.Swagger.SwaggerGenerator。<> c__DisplayClass12.b__11(ApiParameterDescription paramDesc)\ r \ n在System.Linq.Enumerable.WhereSelectEnumerableIterator 2.MoveNext()\r\n at System.Collections.Generic.List 1。 .ctor(IEnumerable 1 collection)\r\n at System.Linq.Enumerable.ToList[TSource](IEnumerable 1源)\ r \ n在Swashbuckle.Swagger.SwaggerGenerator.CreateOperation(ApiDescription apiDesc,SchemaRegistry schemaRegistry)\ r \ n在Swashbuckle.Swagger.SwaggerGenerator.CreatePathItem(IEnumerable 1 apiDescriptions, SchemaRegistry schemaRegistry)\r\n at Swashbuckle.Swagger.SwaggerGenerator.<>c__DisplayClass7.<GetSwagger>b__4(IGrouping 2组)\ r \ n(位于System.Linq.E) numerable.ToDictionary [TSource,TKey,TElement](IEnumerable 1 source, Func 2 keySelector,Func 2 elementSelector, IEqualityComparer 1比较器)\ r \ n在Swashbuckle.Swagger.SwaggerGenerator.GetSwagger(String rootUrl,String apiVersion)\ r \ n在Swashbuckle.Application.SwaggerDocsHandler.SendAsync(HttpRequestMessage请求,CancellationToken cancelleToken)\ r \ n在System.Net.Http.HttpMessageInvoker.SendAsync(HttpRequestMessage请求,CancellationToken cancelToken)\ r \ n在System.Web.Http.Dispatcher .HttpRoutingDispatcher.SendAsync(HttpRequestMessage请求,CancellationToken cancelToken)\ r \ n在System.Net.Http.DelegatingHandler.SendAsync(HttpRequestMessage请求,CancellationToken cancellingToken)\ r \ n在System.Web.Http.HttpServer.d__0.MoveNext() “} http://localhost:5352/swagger/docs/v1

2 个答案:

答案 0 :(得分:0)

出现此错误时,是因为我的ResponseType定义(WebApi)中有错误/遗漏。编译器很好用,但是Swagger不好用。

失败

[ResponseType(typeof(IEnumerable<>))]

工作

[ResponseType(typeof(IEnumerable<string>))]

答案 1 :(得分:-2)

我有所有Controller的基类,这是一个问题。

我已固定使用此解决方案。

[ApiExplorerSettings(IgnoreApi = true)]解决了我的问题,谢谢。作为对其他可能需要此功能的人的补充/说明。如果将其放在基本控制器本身上,它将隐藏所有子控制器(不好),但是如果将其放在属性/方法本身上,它将正确显示子控制器。