OmniSharp / OmniSharp/csharp-language-server-protocol

Nullpointer Exception when using WithLoggerFactory

Open
#913 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
638
Forks
109
Avg merge
1m
Merged PRs (30d)
2

Description

If I use a separate logger factory with its own ILogger interface implementation for the WithLoggerFactory call, then it is not possible to simply return zero in the implementation of the ILogger.BeginScope function.
This leads to a null pointer exception in TimeLoggerExtensions.Disposable.Dispose, because it is not checked here whether the member variable "Disposable" is set at all.
You can work around this by returning "new CompositeDisposable()" in ILogger.BeginScope, for example.
But you have to know that. This is not recognisable from the error message. I have not found anything about this in the documentation.
My suggestion would be to simply modify the Dispose function:

            public void Dispose()
            {
                _sw.Stop();
                _action(_sw.ElapsedMilliseconds);
                _disposable?.Dispose();
            }

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating TimeLoggerExtensions.Disposable.Dispose and the ILogger.BeginScope implementation used by WithLoggerFactory. Reproduce the null reference with a logger that returns zero from BeginScope, then verify that disposal safely handles the missing disposable without changing the normal logging behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
devtools
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.