Swagger使用Newtonsoft序列化时无法加载API定义

时间:2019-03-26 21:59:26

标签: asp.net-core json.net swagger

我正在使用Swashbuckle.AspNetCore软件包来记录我的API。在开始对某些类进行JSON序列化之前,我已经使用了数周。现在我在Swagger用户界面中出现错误:

"Failed to load API definition" - Fetch error Internal Server Error /swagger/v1/swagger.json

我的日志文件显示以下错误:

  

System.IO.FileLoadException:无法加载文件或程序集   'Newtonsoft.Json,版本= 1.2.0.0.0,文化=中性,   PublicKeyToken = 30ad4fe6b2a6aeed”。找到的程序集清单   定义与程序集引用不匹配。 (来自的例外   HRESULT:0x80131040)

我更新到Newtonsoft.Json v12.0.1。 Swagger NuGet软件包是否依赖于Newtonsoft的早期版本?

我尝试更新整个解决方案以使用Newtonsoft.Json v12.0.1。 我还搜索了Swagger与Newtonsoft可能存在的任何依赖关系,但是我没有看到任何明确的内容。

2019-03-26 17:17:34.573 -04:00 [Information] Request starting HTTP/1.1 GET http://localhost:8080/swagger/index.html  
2019-03-26 17:17:34.680 -04:00 [Information] Request finished in 108.7888ms 200 text/html
2019-03-26 17:17:34.876 -04:00 [Information] Request starting HTTP/1.1 GET http://localhost:8080/swagger/v1/swagger.json  
2019-03-26 17:17:34.898 -04:00 [Information] Request starting HTTP/1.1 GET http://localhost:8080/swagger/favicon-32x32.png  
2019-03-26 17:17:34.916 -04:00 [Information] Sending file. Request path: '"/favicon-32x32.png"'. Physical path: '"N/A"'
2019-03-26 17:17:34.917 -04:00 [Information] Request finished in 18.8478ms 200 image/png
2019-03-26 17:17:35.032 -04:00 [Error] Connection ID ""16573246634629012016"", Request ID ""80001a32-0001-e600-b63f-84710c7967bb"": An unhandled exception was thrown by the application.
System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
   at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
   at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
   at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
   at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
   at System.Reflection.CustomAttribute.IsCustomAttributeDefined(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Int32 attributeCtorToken, Boolean mustBeInheritable)
   at System.Reflection.CustomAttribute.IsDefined(RuntimePropertyInfo property, RuntimeType caType)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.GetSerializableMembers(Type objectType)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateProperties(Type type, MemberSerialization memberSerialization)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateObjectContract(Type objectType)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract(Type objectType)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract(Type type)
   at Swashbuckle.AspNetCore.SwaggerGen.SchemaRegistry.CreateSchema(Type type, Queue`1 referencedTypes)
   at Swashbuckle.AspNetCore.SwaggerGen.SchemaRegistry.GetOrRegister(Type type)
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.CreateResponse(ApiResponseType apiResponseType, ISchemaRegistry schemaRegistry)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.CreateResponses(ApiDescription apiDescription, ISchemaRegistry schemaRegistry)
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.CreateOperation(ApiDescription apiDescription, ISchemaRegistry schemaRegistry)
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.CreatePathItem(IEnumerable`1 apiDescriptions, ISchemaRegistry schemaRegistry)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.CreatePathItems(IEnumerable`1 apiDescriptions, ISchemaRegistry schemaRegistry)
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwagger(String documentName, String host, String basePath, String[] schemes)
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
   at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT`1.ProcessRequestAsync()


2019-03-26 17:17:35.058 -04:00 [Information] Request finished in 182.3632ms 500 

我希望招摇的页面像往常一样列出我的HTTP方法。

0 个答案:

没有答案