Skip to content

Conversation

@saitama951
Copy link
Contributor

This is on platforms where the Mono SDK is supported.

When Mono JIT compiles Main(), it encounters a call to new ConsoleRunner(). Unlike CoreCLR, Mono JIT attempts to resolve all field types of ConsoleRunner at JIT compilation time, rather than deferring resolution until runtime.
The problem arises because some fields inside ConsoleRunner depend on assemblies that are only resolvable via the assembly resolve event handler. However, this resolve handler is only installed after Main() has been compiled and execution starts. As a result, Mono JIT fails when it attempts to load these types too early, leading to runtime errors.

This is a workaround for a limitation in Mono JIT by moving the instantiation to an another function.

Allow Main() to execute first**, ensuring that the assembly resolve handler is installed before ConsoleRunner is instantiated

see: dotnet/runtime#60550

@saitama951
Copy link
Contributor Author

cc: @akoeplinger

@saitama951 saitama951 force-pushed the workaround-xunit-mismatch branch 2 times, most recently from 9da89ee to 1d33a8d Compare January 29, 2025 18:45
This is on platforms where the Mono SDK is supported.

When Mono JIT compiles `Main()`, it encounters a call to `new ConsoleRunner()`.
Unlike CoreCLR, Mono JIT **attempts to resolve all field types of ConsoleRunner at JIT compilation time**,
rather than deferring resolution until runtime.
The problem arises because some fields inside `ConsoleRunner` depend
on **assemblies that are only resolvable via the assembly resolve
event handler**. However, this resolve handler is **only installed
after Main() has been compiled and execution starts**.
As a result, Mono JIT fails when it attempts to load these types too early, leading to runtime errors.

This is a workaround for a limitation in Mono JIT by moving the instantiation
to an another function.

Allow `Main()` to execute first**, ensuring that the assembly resolve handler is installed **before**
`ConsoleRunner` is instantiated

see: dotnet/runtime#60550
@saitama951 saitama951 force-pushed the workaround-xunit-mismatch branch from 1d33a8d to f0188b7 Compare January 29, 2025 18:52
Copy link
Member

@akoeplinger akoeplinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@akoeplinger akoeplinger enabled auto-merge (squash) January 29, 2025 20:40
@akoeplinger akoeplinger merged commit 173b74c into dotnet:main Jan 30, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants