question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exception caught in global error handler, exception message: Object reference not set to an instance of an object.

See original GitHub issue

Expected 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:open
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
ntruongvuxcommented, Jul 3, 2023

Maybe, you configured duplication the endpoint about downstream/upstream url

1reaction
klaudiusz-czaplacommented, Jul 3, 2023

@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 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Object Reference Not Set to an Instance of an Object
This infamous and dreaded error message happens when you get a NullReferenceException. This exception is thrown when you try to access a member—for...
Read more >
What does "Object reference not set to an instance of an ...
Most of the time, when you try to assing value into object, and if the value is null, then this kind of exception...
Read more >
Fix: "Object Reference Not Set to an Instance of ...
The error message "Object reference not set to an instance of an object" means that perhaps you're referring to an object that doesn't...
Read more >
How to Fix Object Reference Not Set to an Instance of ...
We have learned that the nullreferenceexception:object reference not set to an instance of an object is caused by a null reference.
Read more >
How to Fix Object Reference Not Set To An Instance of an Object
Error Message : Object Reference Not Set To An Instance of an Object Subscribe for uipath tutorial videos The error : " Object...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found