[release/7.0] [hot_reload] Fix unresolved token when new nested structs are used #76625
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.
Backport of #76618 to release/7.0
/cc @lambdageek
Customer Impact
Customers using .NET 7 hot reload on iOS/Android/WebAssembly may experience application crashes if using the new .NET 7 capability to add new class definitions during a hot reload session.
In .NET 7 for iOS/Android/WebAssembly it is now possible to add new methods (to existing classes) as well as newly defined classes/structs/enums during a hot reload session. However in some circumstances (when a new nested struct definition is used as the type of a field in a new class) adding such new definitions causes the runtime to crash.
Testing
New CI test; manual testing.
Risk
Low or Moderate. The fix involves causing the runtime loader to delay initializing the MonoClass that represents the nested struct. It is possible that not every code path that attempts to use the new field actually does this initialization. I have attempted to verify that class fields are used by the mono interpreter only after explicitly initializing them, or through accessor methods that explicitly initialize them. However it is possible that fixing this regression may uncover other underlying issues.
On the other hand in all such cases it should be possible to simply restart the app. It's not the ideal developer inner loop, but it would not leave the developer completely blocked.
None of the changes here impact apps deployed in production.