Fix NullReferenceException in background thread emitting IL in DependencyInjection...
authorEric Erhardt <eric.erhardt@microsoft.com>
Thu, 8 Jul 2021 20:29:10 +0000 (15:29 -0500)
committerGitHub <noreply@github.com>
Thu, 8 Jul 2021 20:29:10 +0000 (15:29 -0500)
commit24329262b88fd29951a7b561169c12e82c668b19
tree91f1e6cba98989175cccde6bc9903574bfa731ae
parent7ae4d1acbc73b5d8e3f79797e5e73d5a546e8470
Fix NullReferenceException in background thread emitting IL in DependencyInjection (#55340)

* Fix NullReferenceException in background thread emitting IL in DependencyInjection

When ILEmitResolverBuilder is getting created, it grabs the "Root" scope off of the ServiceProvider. However, the Root scope isn't set on ServiceProvider yet. So later when it tries to get used, it null refs. But this exception gets caught and eaten since it happens on a background thread.

The fix is to set Root before creating the ServiceProviderEngine.

* Add a debug assert that we shouldn't get exceptions from the background compilation thread
src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/DynamicServiceProviderEngine.cs
src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceProvider.cs