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
- Add tests for IServiceProvider.GetRequiredService No repro for #210 — committed to DotNetAnalyzers/IDisposableAnalyzers by JohanLarsson 4 years ago
- More repro attempts. #210 — committed to DotNetAnalyzers/IDisposableAnalyzers by JohanLarsson 4 years ago
- More test cases for IServiceProvider.GetRequiredService. Still no repro for #210 — committed to DotNetAnalyzers/IDisposableAnalyzers by JohanLarsson 4 years ago
- Repro for https://github.com/DotNetAnalyzers/IDisposableAnalyzers/issues/210 — committed to jeremyVignelles/repro-idispanalyzers by jeremyVignelles 4 years ago
I managed to reproduce, the issue only happen when
<Nullable>enable</Nullable>
is set on the projectSee https://github.com/jeremyVignelles/repro-idispanalyzers/commit/a0d63e9449354511b2830827771443097d68c9db#diff-9dbd58148108742e0731215aa147f9d6R35
I see it now in ValidCode.NetCore
@JohanLarsson : Can the “needs-repro” tag be removed here?