WebApi
WebApi copied to clipboard
EDM model exception of OData not caught in global exception handler
Short summary (3-5 sentences) describing the issue.
When providing the wrong input parameter in the OData function i.e. string instead of integer then ODataException is thrown which is not caught in the global exception handler and below error is returned:
Microsoft.OData.ODataException: The parameter value ($234) from request is not valid. The parameter value should be format of type 'Edm.Int64'. ---> Microsoft.OData.ODataException: Expected literal type token but found token '$234'. at Microsoft.OData.UriParser.ExpressionLexerLiteralExtensions.ReadLiteralToken(ExpressionLexer expressionLexer) at Microsoft.OData.ODataUriUtils.ConvertFromUriLiteral(String value, ODataVersion version, IEdmModel model, IEdmTypeReference typeReference) at Microsoft.AspNetCore.OData.Routing.Template.SegmentTemplateHelpers.Match(ODataTemplateTranslateContext context, IEdmFunction function, IDictionary'2 parameterMappings) --- End of inner exception stack trace --- at Microsoft.AspNetCore.OData.Routing.Template.SegmentTemplateHelpers.Match(ODataTemplateTranslateContext context, IEdmFunction function, IDictionary' parameterMappings) at Microsoft.AspNetCore.OData.Routing.Template.FunctionSegmentTemplate.TryTranslate(ODataTemplateTranslateContext context) at Microsoft.AspNetCore.OData.Routing.Template.DefaultODataTemplateTranslator.Translate(ODataPathTemplate path, ODataTemplateTranslateContext context) at Microsoft.AspNetCore.OData.Routing.ODataRoutingMatcherPolicy.ApplyAsync(HttpContext httpContext, CandidateSet candidates) at Microsoft.AspNetCore.Routing.Matching.DfaMatcher.SelectEndpointWithPoliciesAsync(HttpContext httpContext, IEndpointSelectorPolicy[] policies, CandidateSet candidateSet) at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.<Invoke>g__AwaitMatch|8_1(EndpointRoutingMiddleware middleware, HttpContext httpContext, Task matchTask) at Serilog.AspNetCore.RequestLoggingMiddleware.Invoke(HttpContext httpContext) at CorrelationId.CorrelationIdMiddleware.Invoke(HttpContext context, ICorrelationContextFactory correlationContextFactory) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
Assemblies affected
Microsoft.OData 8.0.6 NuGet package
Reproduce steps
Attached screenshot of the issue.
Expected result
The exception should be handled in the global exception handler.
Actual result
The exception is not being handled in the global exception handler.
Additional detail
- When providing an invalid value like providing $234 instead of long value 234 in the request parameter id then OData exception is thrown which is not caught in the global exception handler.
Hi @gohilravi thank you for reporting this. Could you share more info about your implementation, and in particular, what you global exception handler looks like?
Hi @gohilravi thank you for reporting this. Could you share more info about your implementation, and in particular, what you global exception handler looks like?
Hi @habbes it is a simple exception handler as suggested by the .NET core. Attached global exception handler registration logic and its logic with you.

@habbes Did you get a chance to review the previous comment?
Any update on this? Seems to be a common issue, especially with folks that have QA testers that send in all kinds of data in testing.
We are seeing the same issue in Microsoft.OData 8.0.10 NuGet package. Any updates on this? Looks like this is a common issue in the OData library.
@habbes Do you have any update on this issue? It appears to be quite common. We are still seeing this issue as well. Do you have an estimate or update on a solution?
@habbes Any update on this?
@gohilravi Any update on your issue? Did you manage to solve it?