Swagger Failed to load API Definition when using Newtonsoft Serialization

2

I'm using Swashbuckle.AspNetCore package to document my API. I had it working for weeks until I started JSON serialization of some classes. Now I get an error in the Swagger UI :

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

My log files show the following error:

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)

I updated to Newtonsoft.Json v12.0.1. Does the Swagger NuGet package depend on a previous version of Newtonsoft?

I tried updating my entire solution to use Newtonsoft.Json v12.0.1. I also searched for any possible dependencies Swagger may have with Newtonsoft, but I did not see anything explicit.

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 

I expect the swagger page to list my HTTP methods as usual.

asp.net-core
json.net
swagger
asked on Stack Overflow Mar 26, 2019 by hcode • edited Mar 27, 2019 by Moien Tajik

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0