#asp.net-core #json.net #swagger
#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, версия = 12.0.0.0, Культура = нейтральная, PublicKeyToken =30ad4fe6b2a6aeed’. Определение манифеста найденной сборки не соответствует ссылке на сборку. (Исключение из HRESULT: 0x80131040)
Я обновился до Newtonsoft.Json v12.0.1. Зависит ли пакет Swagger NuGet от предыдущей версии Newtonsoft?
Я попытался обновить все свое решение, чтобы использовать Newtonsoft.Json версии 12.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, Assemblyamp; lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeTypeamp; attributeType, IRuntimeMethodInfoamp; ctor, Booleanamp; ctorHasParameters, Booleanamp; 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
Я ожидаю, что на странице swagger будут перечислены мои HTTP-методы, как обычно.