-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[HotReloadAgent] fix possible NullReferenceException
#52367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jonathanpeppers
merged 4 commits into
release/10.0.2xx
from
dev/peppers/HotReloadAgentNRE
Jan 10, 2026
Merged
[HotReloadAgent] fix possible NullReferenceException
#52367
jonathanpeppers
merged 4 commits into
release/10.0.2xx
from
dev/peppers/HotReloadAgentNRE
Jan 10, 2026
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When running on a platform like Android, startup hooks can run via
.NET's `runtimeconfig.json`, such as:
<ItemGroup>
<RuntimeHostConfigurationOption Include="STARTUP_HOOKS" Value="Microsoft.Extensions.DotNetDeltaApplier" />
</ItemGroup>
If done this way, `$DOTNET_STARTUP_HOOKS` can be `null`, leading to:
01-08 16:07:49.336 14598 14598 F mono-rt : System.NullReferenceException: Object reference not set to an instance of an object.
01-08 16:07:49.336 14598 14598 F mono-rt : at Microsoft.DotNet.HotReload.HotReloadAgent.RemoveCurrentAssembly(Type startupHookType, String environment)
01-08 16:07:49.336 14598 14598 F mono-rt : at Microsoft.DotNet.HotReload.HotReloadAgent.ClearHotReloadEnvironmentVariables(Type startupHookType)
01-08 16:07:49.336 14598 14598 F mono-rt : at StartupHook.Initialize()
01-08 16:07:49.336 14598 14598 F mono-rt : at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
01-08 16:07:49.336 14598 14598 F mono-rt : at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
01-08 16:07:49.336 14598 14598 F mono-rt : --- End of inner exception stack trace ---
01-08 16:07:49.336 14598 14598 F mono-rt : at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
01-08 16:07:49.336 14598 14598 F mono-rt : at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
01-08 16:07:49.336 14598 14598 F mono-rt : at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
01-08 16:07:49.336 14598 14598 F mono-rt : at System.StartupHookProvider.CallStartupHook(StartupHookNameOrPath startupHook)
01-08 16:07:49.336 14598 14598 F mono-rt : at System.StartupHookProvider.ProcessStartupHooks(String diagnosticStartupHooks)
I think we should remove the `!` and do a better null check, to just
prevent this from happening.
I don't know yet if we'll use the env var or the `runtimeconfig.json`
by default, but this seems reasonable to fix.
With the fix, it makes it to an expected state:
01-08 16:20:20.560 17468 17468 I DOTNET : [HotReload] Environment variable DOTNET_WATCH_HOTRELOAD_NAMEDPIPE_NAME has no value
47 tasks
Contributor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a NullReferenceException in the HotReloadAgent that occurs on platforms like Android where startup hooks can be configured via runtimeconfig.json instead of environment variables, resulting in a null DOTNET_STARTUP_HOOKS variable.
Key changes:
- Remove null-forgiving operator when retrieving environment variable
- Update
RemoveCurrentAssemblyto accept nullable string parameter - Use
string.IsNullOrEmpty()for more robust null/empty checking
tmat
reviewed
Jan 9, 2026
tmat
reviewed
Jan 9, 2026
tmat
approved these changes
Jan 9, 2026
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When running on a platform like Android, startup hooks can run via .NET's
runtimeconfig.json, such as:If done this way,
$DOTNET_STARTUP_HOOKScan benull, leading to:I think we should remove the
!and do a better null check, to just prevent this from happening.I don't know yet if we'll use the env var or the
runtimeconfig.jsonby default, but this seems reasonable to fix.With the fix, it makes it to an expected state: