IDisposableAnalyzers: IDISP004 should not be triggered for serviceProvider.GetRequiredService() in nullable context

The purpose of the service provider is to create and dispose the instances it contains. Thus, this line should not trigger a IDISP004.

new MyObject(this._serviceProvider.GetRequiredService<ILoggerFactory>());

EDIT: It seems to only happen when in a nullability-aware context, see below

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 20

Commits related to this issue

Most upvoted comments

I managed to reproduce, the issue only happen when <Nullable>enable</Nullable> is set on the project

See https://github.com/jeremyVignelles/repro-idispanalyzers/commit/a0d63e9449354511b2830827771443097d68c9db#diff-9dbd58148108742e0731215aa147f9d6R35

image

I see it now in ValidCode.NetCore

@JohanLarsson : Can the “needs-repro” tag be removed here?