Remove module-level [SkipLocalsInit] to prevent native crashes on AOT platforms (iOS/Android) #874
+0
−7
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.
This PR removes the following directive:
to resolve native crashes on mobile platforms (specifically catched on iOS and Android when using .NET 9 in MAUI app).
🧯 The Problem
In high-throughput UI scenarios (e.g. extremely fast list scrolling in MAUI), calls to:
began randomly triggering crashes. After isolating the issue, removing [SkipLocalsInit] fully resolved the problem.
Removing it ensures cross-platform safety and improves compatibility mobile/AOT targets.
Issue describing the case: #873
"This attribute is unsafe, because it may reveal uninitialized memory to the application in certain instances (for example, reading from uninitialized stack-allocated memory). If applied to a method directly, the attribute applies to that method and all its nested functions, including lambdas and local functions. If applied to a type or module, it applies to all methods nested inside. This attribute is intentionally not permitted on assemblies. To apply the attribute to multiple type declarations, use it at the module level instead."
— docs.microsoft.com
🚀 Impact
Fixes crashes in mobile apps using Markdig. Improves confidence for developers using Markdig in MAUI, Unity, Blazor Hybrid, and other non-Windows environments.
Please let me know if you'd prefer the attribute be conditionally compiled or applied to only select methods, would happy to adjust.