Exception caught in global error handler, exception message: Object reference not set to an instance of an object.
See original GitHub issueExpected Behavior
I’m expecting to get error details coming from ocelot.json file validation in case of invalid configuration being provided.
Actual Behavior
I had scenario where Errors collection coming from validation process (ocelot.json) is discarded and then I’m getting NullReferenceException instead which is hiding the real problem.
Exception caught in global error handler, exception message: Object reference not set to an instance of an object., exception stack:
at Ocelot.Errors.Middleware.ExceptionHandlerMiddleware.TrySetGlobalRequestId(HttpContext httpContext, IInternalConfiguration configuration)\n
at Ocelot.Errors.Middleware.ExceptionHandlerMiddleware.Invoke(HttpContext httpContext)
Steps to Reproduce the Problem
You have to create ocelot.json file where one of the routes contains sth like this: “DownstreamPathTemplate”: “{everything}”
During debugging Ocelot I got at some point Errors collection with message: “Downstream Path Template {everything} doesnt start with forward slash” It was in method Ocelot.Middleware.OcelotMiddlewareExtensions.CreateConfiguration’IApplicationBuilder -> fileConfig.OnChange callback
Ocelot.dll!Ocelot.Configuration.Repository.InMemoryInternalConfigurationRepository.AddOrReplace(Ocelot.Configuration.IInternalConfiguration internalConfiguration) Line 27 C#
> Ocelot.dll!Ocelot.Middleware.OcelotMiddlewareExtensions.CreateConfiguration.AnonymousMethod__0(Ocelot.Configuration.File.FileConfiguration config) Line 98 C#
Microsoft.Extensions.Options.dll!Microsoft.Extensions.Options.OptionsMonitorExtensions.OnChange.AnonymousMethod__0(System.__Canon o, string _) Unknown
nevertheless somehow this mesage was never logged anywhere, it was discarded and finally I got NullReferenceException instead
{Ocelot.Responses.ErrorResponse<Ocelot.Configuration.IInternalConfiguration>} -> Data -> null in my case -> Errors -> Downstream Path Template {everything} doesnt start with forward slash -> IsError -> true
In line
internalConfigRepo.AddOrReplace(newInternalConfig.Data);
error should be checked before accessing .Data property
Specifications
- Version: 17.0.0, 17.0.1
- Platform: Windows/Linux
- Subsystem: -
Issue Analytics
- State:
- Created a year ago
- Comments:6 (4 by maintainers)
Maybe, you configured duplication the endpoint about downstream/upstream url
@raman-m Error message which I’ve posted was extracted by myself during debugging. In the runtime it was hidden from the user. Btw NullReferenceException should never be thrown by the application. It should be handled somehow. As I said - original error message was hidden. Without debugging Ocelot code I would never be able to get to know what was wrong and misconfigured 😃