CoreWCF icon indicating copy to clipboard operation
CoreWCF copied to clipboard

OpenApiSchemaBuilder.GetMethodUriWebInvoke can throw NullReferenceException

Open yowl opened this issue 3 years ago • 3 comments

If swagger is turned on, then CoreWCF can make it fail to show its UI with exception Object reference not set to an instance of an object. Stack is

at CoreWCF.OpenApi.OpenApiSchemaBuilder.GetMethodUriWebInvoke(MethodInfo methodInfo)
at CoreWCF.OpenApi.OpenApiSchemaBuilder.PopulateOpenApiPath(OpenApiDocument document, MethodInfo methodInfo, IEnumerable`1 tagsToHide, String additionalBasePath, WebMessageFormat behaviorFormat, Func`2 getOperationInfo)
at CoreWCF.OpenApi.OpenApiSchemaBuilder.PopulateOpenApiPathsOperations(OpenApiDocument document, IEnumerable`1 contracts, IEnumerable`1 tagsToHide)
at CoreWCF.OpenApi.OpenApiSchemaBuilder.BuildOpenApiSpecificationDocument(OpenApiOptions info, IEnumerable`1 contracts)
at CoreWCF.OpenApi.OpenApiDocumentProvider.GetSwagger(String documentName, String host, String basePath)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)

As this is a project where conversion from net framework to net core is a WIP, its likely I've not got everything right, but some clues in the error message would be helpful.

yowl avatar Jun 20 '22 12:06 yowl

I think I see the issue. Do you have an endpoint with a WebInvoke attribute that doesn't have a Method set? If that is the case I'll put in a PR to fix this.

JonathanHopeDMRC avatar Jun 23 '22 20:06 JonathanHopeDMRC

yes , lots e.g.

        [WebInvoke]
        public List<GradeResult> UpdateGrades(List<GradeAction> actions)
        {

yowl avatar Jun 23 '22 20:06 yowl

Then I think this PR will fix it: https://github.com/CoreWCF/CoreWCF/pull/729.

JonathanHopeDMRC avatar Jun 23 '22 21:06 JonathanHopeDMRC