{"id":24084073,"url":"https://github.com/augustoproiete-repros/repro-nswag-jsonpatchdocument-nre","last_synced_at":"2026-06-13T17:04:29.697Z","repository":{"id":84620242,"uuid":"310686170","full_name":"augustoproiete-repros/repro-nswag-jsonpatchdocument-nre","owner":"augustoproiete-repros","description":"Minimal, Reproducible example of NullReferenceException when using NSwag and JsonPatchDocument\u003cT\u003e","archived":false,"fork":false,"pushed_at":"2020-11-15T01:38:06.000Z","size":69,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-27T01:53:29.171Z","etag":null,"topics":["jsonpatch","jsonpatchdocument","nswag","null-reference-exception"],"latest_commit_sha":null,"homepage":"https://github.com/RicoSuter/NSwag/issues/3147","language":"C#","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/augustoproiete-repros.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-06T19:17:45.000Z","updated_at":"2021-01-04T00:38:47.000Z","dependencies_parsed_at":"2023-03-06T19:30:41.561Z","dependency_job_id":null,"html_url":"https://github.com/augustoproiete-repros/repro-nswag-jsonpatchdocument-nre","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/augustoproiete-repros/repro-nswag-jsonpatchdocument-nre","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/augustoproiete-repros%2Frepro-nswag-jsonpatchdocument-nre","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/augustoproiete-repros%2Frepro-nswag-jsonpatchdocument-nre/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/augustoproiete-repros%2Frepro-nswag-jsonpatchdocument-nre/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/augustoproiete-repros%2Frepro-nswag-jsonpatchdocument-nre/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/augustoproiete-repros","download_url":"https://codeload.github.com/augustoproiete-repros/repro-nswag-jsonpatchdocument-nre/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/augustoproiete-repros%2Frepro-nswag-jsonpatchdocument-nre/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34292326,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-13T02:00:06.617Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["jsonpatch","jsonpatchdocument","nswag","null-reference-exception"],"created_at":"2025-01-10T00:19:19.218Z","updated_at":"2026-06-13T17:04:29.692Z","avatar_url":"https://github.com/augustoproiete-repros.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"## NSwag: `NullReferenceException` when using `JsonPatchDocument\u003cT\u003e`\n\n\u003e https://github.com/RicoSuter/NSwag/issues/3147\n\nI get a `NullReferenceException` if I have any controller receiving a `JsonPatchDocument\u003cT\u003e` instance.\n\n\n![Exception screenshot](asset/exception-screenshot.png)\n\n```csharp\n[ApiController]\n[Route(\"[controller]\")]\npublic class WeatherForecastController : ControllerBase\n{\n    [HttpPatch]\n    public ActionResult PartialUpdate([FromBody] JsonPatchDocument\u003cUpdateWeatherForecast\u003e update)\n    {\n        return Ok();\n    }\n}\n```\n\n```csharp\nusing System.Threading.Tasks;\nusing Microsoft.AspNetCore.Http;\n\nnamespace ReproNSwagJsonPatchDocumentNRE\n{\n    public class SomeMiddleware\n    {\n        private readonly RequestDelegate _next;\n\n        public SomeMiddleware(RequestDelegate next)\n        {\n            _next = next;\n        }\n\n        public async Task Invoke(HttpContext httpContext)\n        {\n            await _next(httpContext); // BOOM!\n        }\n    }\n}\n```\n\n### Run the project in Debug Mode (F5)\n\n```\nSystem.NullReferenceException: 'Object reference not set to an instance of an object.'\n    Newtonsoft.Json.dll!Newtonsoft.Json.Serialization.DefaultContractResolver.CreateShouldSerializeTest.AnonymousMethod__0(object o)    Unknown\n```\n\nCall Stack:\n\n```    \n[Lightweight Function]\nNewtonsoft.Json.dll!Newtonsoft.Json.Serialization.DefaultContractResolver.CreateShouldSerializeTest.AnonymousMethod__0(object o)\nNJsonSchema.dll!NJsonSchema.Generation.JsonSchemaGenerator.GenerateProperties(System.Type type, NJsonSchema.JsonSchema schema, NJsonSchema.Generation.JsonSchemaResolver schemaResolver)\nNJsonSchema.dll!NJsonSchema.Generation.JsonSchemaGenerator.GenerateInheritance(Namotion.Reflection.ContextualType type, NJsonSchema.JsonSchema schema, NJsonSchema.Generation.JsonSchemaResolver schemaResolver)\nNJsonSchema.dll!NJsonSchema.Generation.JsonSchemaGenerator.GenerateObject(NJsonSchema.JsonSchema schema, NJsonSchema.Generation.JsonTypeDescription typeDescription, NJsonSchema.Generation.JsonSchemaResolver schemaResolver)\nNSwag.Generation.dll!NSwag.Generation.OpenApiSchemaGenerator.GenerateObject(NJsonSchema.JsonSchema schema, NJsonSchema.Generation.JsonTypeDescription typeDescription, NJsonSchema.Generation.JsonSchemaResolver schemaResolver)\nNJsonSchema.dll!NJsonSchema.Generation.JsonSchemaGenerator.Generate\u003cNJsonSchema.JsonSchema\u003e(NJsonSchema.JsonSchema schema, Namotion.Reflection.ContextualType contextualType, NJsonSchema.Generation.JsonSchemaResolver schemaResolver)\nNJsonSchema.dll!NJsonSchema.Generation.JsonSchemaGenerator.Generate\u003cNJsonSchema.JsonSchema\u003e(Namotion.Reflection.ContextualType contextualType, NJsonSchema.Generation.JsonSchemaResolver schemaResolver)\nNJsonSchema.dll!NJsonSchema.Generation.JsonSchemaGenerator.GenerateWithReferenceAndNullability\u003cNJsonSchema.JsonSchema\u003e(Namotion.Reflection.ContextualType contextualType, bool isNullable, NJsonSchema.Generation.JsonSchemaResolver schemaResolver, System.Action\u003cNJsonSchema.JsonSchema, NJsonSchema.JsonSchema\u003e transformation)\nNSwag.Generation.dll!NSwag.Generation.OpenApiSchemaGenerator.GenerateWithReferenceAndNullability\u003cNJsonSchema.JsonSchema\u003e(Namotion.Reflection.ContextualType contextualType, bool isNullable, NJsonSchema.Generation.JsonSchemaResolver schemaResolver, System.Action\u003cNJsonSchema.JsonSchema, NJsonSchema.JsonSchema\u003e transformation)\nNJsonSchema.dll!NJsonSchema.Generation.JsonSchemaGenerator.GenerateArray\u003cNJsonSchema.JsonSchema\u003e(NJsonSchema.JsonSchema schema, NJsonSchema.Generation.JsonTypeDescription typeDescription, NJsonSchema.Generation.JsonSchemaResolver schemaResolver)\nNJsonSchema.dll!NJsonSchema.Generation.JsonSchemaGenerator.Generate\u003cNJsonSchema.JsonSchema\u003e(NJsonSchema.JsonSchema schema, Namotion.Reflection.ContextualType contextualType, NJsonSchema.Generation.JsonSchemaResolver schemaResolver)\nNJsonSchema.dll!NJsonSchema.Generation.JsonSchemaGenerator.Generate\u003cNJsonSchema.JsonSchema\u003e(Namotion.Reflection.ContextualType contextualType, NJsonSchema.Generation.JsonSchemaResolver schemaResolver)\nNJsonSchema.dll!NJsonSchema.Generation.JsonSchemaGenerator.GenerateWithReferenceAndNullability\u003cNJsonSchema.JsonSchema\u003e(Namotion.Reflection.ContextualType contextualType, bool isNullable, NJsonSchema.Generation.JsonSchemaResolver schemaResolver, System.Action\u003cNJsonSchema.JsonSchema, NJsonSchema.JsonSchema\u003e transformation)\nNSwag.Generation.dll!NSwag.Generation.OpenApiSchemaGenerator.GenerateWithReferenceAndNullability\u003cNJsonSchema.JsonSchema\u003e(Namotion.Reflection.ContextualType contextualType, bool isNullable, NJsonSchema.Generation.JsonSchemaResolver schemaResolver, System.Action\u003cNJsonSchema.JsonSchema, NJsonSchema.JsonSchema\u003e transformation)\nNSwag.Generation.AspNetCore.dll!NSwag.Generation.AspNetCore.Processors.OperationParameterProcessor.AddBodyParameter(NSwag.Generation.Processors.Contexts.OperationProcessorContext context, NSwag.Generation.AspNetCore.Processors.OperationParameterProcessor.ExtendedApiParameterDescription extendedApiParameter)\nNSwag.Generation.AspNetCore.dll!NSwag.Generation.AspNetCore.Processors.OperationParameterProcessor.Process(NSwag.Generation.Processors.Contexts.OperationProcessorContext operationProcessorContext)\nNSwag.Generation.AspNetCore.dll!NSwag.Generation.AspNetCore.AspNetCoreOpenApiDocumentGenerator.RunOperationProcessors(NSwag.OpenApiDocument document, Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescription apiDescription, System.Type controllerType, System.Reflection.MethodInfo methodInfo, NSwag.OpenApiOperationDescription operationDescription, System.Collections.Generic.List\u003cNSwag.OpenApiOperationDescription\u003e allOperations, NSwag.Generation.OpenApiDocumentGenerator swaggerGenerator, NSwag.OpenApiSchemaResolver schemaResolver)\nNSwag.Generation.AspNetCore.dll!NSwag.Generation.AspNetCore.AspNetCoreOpenApiDocumentGenerator.AddOperationDescriptionsToDocument(NSwag.OpenApiDocument document, System.Type controllerType, System.Collections.Generic.List\u003cSystem.Tuple\u003cNSwag.OpenApiOperationDescription, Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescription, System.Reflection.MethodInfo\u003e\u003e operations, NSwag.Generation.OpenApiDocumentGenerator swaggerGenerator, NSwag.OpenApiSchemaResolver schemaResolver)\nNSwag.Generation.AspNetCore.dll!NSwag.Generation.AspNetCore.AspNetCoreOpenApiDocumentGenerator.GenerateForControllers(NSwag.OpenApiDocument document, System.Linq.IGrouping\u003cSystem.Type, System.Tuple\u003cMicrosoft.AspNetCore.Mvc.ApiExplorer.ApiDescription, Microsoft.AspNetCore.Mvc.Controllers.ControllerActionDescriptor\u003e\u003e[] apiGroups, NSwag.OpenApiSchemaResolver schemaResolver)\nNSwag.Generation.AspNetCore.dll!NSwag.Generation.AspNetCore.AspNetCoreOpenApiDocumentGenerator.GenerateAsync(Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescriptionGroupCollection apiDescriptionGroups)\nNSwag.Generation.AspNetCore.dll!NSwag.Generation.AspNetCore.AspNetCoreOpenApiDocumentGenerator.GenerateAsync(object serviceProvider)\nNSwag.AspNetCore.dll!NSwag.AspNetCore.OpenApiDocumentProvider.GenerateAsync(string documentName)\nNSwag.AspNetCore.dll!NSwag.AspNetCore.Middlewares.OpenApiDocumentMiddleware.GenerateDocumentAsync(Microsoft.AspNetCore.Http.HttpContext context)\nNSwag.AspNetCore.dll!NSwag.AspNetCore.Middlewares.OpenApiDocumentMiddleware.GetDocumentAsync(Microsoft.AspNetCore.Http.HttpContext context)\nNSwag.AspNetCore.dll!NSwag.AspNetCore.Middlewares.OpenApiDocumentMiddleware.Invoke(Microsoft.AspNetCore.Http.HttpContext context)\nMicrosoft.AspNetCore.Routing.dll!Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(Microsoft.AspNetCore.Http.HttpContext httpContext)\nMicrosoft.AspNetCore.Authorization.Policy.dll!Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(Microsoft.AspNetCore.Http.HttpContext context)\nReproNSwagJsonPatchDocumentNRE.dll!ReproNSwagJsonPatchDocumentNRE.SomeMiddleware.Invoke(Microsoft.AspNetCore.Http.HttpContext httpContext) Line 17\n    at C:\\augustoproiete\\repro-nswag-jsonpatchdocument-nre\\src\\ReproNSwagJsonPatchDocumentNRE\\SomeMiddleware.cs(17)\nMicrosoft.AspNetCore.Routing.dll!Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.SetRoutingAndContinue(Microsoft.AspNetCore.Http.HttpContext httpContext)\nMicrosoft.AspNetCore.Routing.dll!Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(Microsoft.AspNetCore.Http.HttpContext httpContext)\nMicrosoft.AspNetCore.Diagnostics.dll!Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(Microsoft.AspNetCore.Http.HttpContext context)\nMicrosoft.AspNetCore.HostFiltering.dll!Microsoft.AspNetCore.HostFiltering.HostFilteringMiddleware.Invoke(Microsoft.AspNetCore.Http.HttpContext context)\nMicrosoft.AspNetCore.Hosting.dll!Microsoft.AspNetCore.Hosting.HostingApplication.ProcessRequestAsync(Microsoft.AspNetCore.Hosting.HostingApplication.Context context)\nMicrosoft.AspNetCore.Server.IIS.dll!Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT\u003cMicrosoft.AspNetCore.Hosting.HostingApplication.Context\u003e.ProcessRequestAsync()\nMicrosoft.AspNetCore.Server.IIS.dll!Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext.HandleRequest()\nMicrosoft.AspNetCore.Server.IIS.dll!Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext.Execute()\nSystem.Private.CoreLib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch()\nSystem.Private.CoreLib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faugustoproiete-repros%2Frepro-nswag-jsonpatchdocument-nre","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faugustoproiete-repros%2Frepro-nswag-jsonpatchdocument-nre","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faugustoproiete-repros%2Frepro-nswag-jsonpatchdocument-nre/lists"}