IDISP004 should not be triggered for serviceProvider.GetRequiredService<T>() in nullable context
See original GitHub issueThe 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
Issue Analytics
- State:
- Created 3 years ago
- Comments:20
Top Results From Across the Web
c# - The non-generic method 'IServiceProvider.GetService ...
GetRequiredService should be used when an application can't work unless a service is available. If an instance can't be created, it will ......
Read more >Nullable reference types
This article provides an overview of nullable reference types. You'll learn how the feature provides safety against null reference ...
Read more >Working with nullable reference types - EF Core
An empty collection means that no related entities exist, but the list itself should never be null . DbContext and DbSet. With EF,...
Read more >Fighting with nullable reference types in Razor Pages
In this post I discuss C#'s nullable reference types in the context of Razor Pages, why they don't play nicely together and how...
Read more >How many of you started using nullable reference types ...
I recently started working on a new project targeting .Net Core 3.1 and plan to switch to .Net5 once it's officially released in...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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