You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Changes in code that only runs once are currently applied during Hot Reload but they never take effect.
Instead of applying such changes Roslyn Hot Reload service should report warning that the change had likely no effect.
The host (IDE/dotnet-watch) may decide to force restart the app when it observes this warning.
It's a non-goal to detect whether or not changes in arbitrary changed code will have effect when applied. That'd be equivalent to solving the Halting problem. However, we can identify scenarios where it's obvious and provide a configuration for application frameworks to participate in the decision.
When to report the warning
Hot Reload will issue a rude edit if the statement or expression being changed is directly
in a top-level code or in Main method,
in a static constructor body,
in a static member initializer
unless an active statement is present in the modified method body (i.e. the change is modifying an active method frame during EnC).
Changes to bodies of local functions and lambdas defined in top-level code are not considered to be directly in the top-level code and thus, by default, won't require restart.
Hot Reload will recognize the following attribute that allows customization of the above behavior:
If this attribute is applied on a method or a local function any change made directly to its body will require restart. Changes to bodies of local functions and lambdas defined within the method/function won't require restart.
If this attribute is applied on a parameter such parameter must be of Delegate type. If a lambda expression is passed directly as an argument to such parameter any change to the body of the lambda will require restart, unless the lambda body itself or any encompassing lambda/function/member body contains an active statement.
Consider:
Adding bool parameter that allows to apply the attribute on Main method and static constructor and change the default behavior
How does the host decide whether or not to restart in presence of the warning?
Scenario: User renames a method that's called from top-level code. They don't care about the "effect" the rename has in top-level code (likely none). It'd be unnecessary to restart the app.
Scenario: User changes app configuration in top-level code. The host should restart, otherwise the app will still use the old configuration.
The text was updated successfully, but these errors were encountered:
tmat
changed the title
EnC: detect changes in top-level code that does not run after applied
EnC: detect changes in code that only runs once and need to force restart
Apr 1, 2025
Changes in code that only runs once are currently applied during Hot Reload but they never take effect.
Instead of applying such changes Roslyn Hot Reload service should report warning that the change had likely no effect.
The host (IDE/dotnet-watch) may decide to force restart the app when it observes this warning.
It's a non-goal to detect whether or not changes in arbitrary changed code will have effect when applied. That'd be equivalent to solving the Halting problem. However, we can identify scenarios where it's obvious and provide a configuration for application frameworks to participate in the decision.
When to report the warning
Hot Reload will issue a rude edit if the statement or expression being changed is directly
Main
method,unless an active statement is present in the modified method body (i.e. the change is modifying an active method frame during EnC).
Changes to bodies of local functions and lambdas defined in top-level code are not considered to be directly in the top-level code and thus, by default, won't require restart.
Hot Reload will recognize the following attribute that allows customization of the above behavior:
If this attribute is applied on a method or a local function any change made directly to its body will require restart. Changes to bodies of local functions and lambdas defined within the method/function won't require restart.
If this attribute is applied on a parameter such parameter must be of
Delegate
type. If a lambda expression is passed directly as an argument to such parameter any change to the body of the lambda will require restart, unless the lambda body itself or any encompassing lambda/function/member body contains an active statement.Consider:
bool
parameter that allows to apply the attribute onMain
method and static constructor and change the default behaviorRelated: CreateNewOnMetadataUpdateAttribute
Host action
How does the host decide whether or not to restart in presence of the warning?
Scenario: User renames a method that's called from top-level code. They don't care about the "effect" the rename has in top-level code (likely none). It'd be unnecessary to restart the app.
Scenario: User changes app configuration in top-level code. The host should restart, otherwise the app will still use the old configuration.
The text was updated successfully, but these errors were encountered: