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.

IDISP004 should not be triggered for serviceProvider.GetRequiredService<T>() in nullable context

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:20

github_iconTop GitHub Comments

jeremyVignellescommented, Mar 27, 2020

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


JohanLarssoncommented, May 6, 2020


I see it now in ValidCode.NetCore

Read more comments on GitHub >

github_iconTop 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 >

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 Post

No results found

github_iconTop Related Hashnode Post

No results found