[PR #874] [CLOSED] Remove module-level [SkipLocalsInit] to prevent native crashes on AOT platforms (iOS/Android) #1267

Open
opened 2026-01-29 14:52:18 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/xoofx/markdig/pull/874
Author: @taublast
Created: 5/25/2025
Status: Closed

Base: masterHead: master


📝 Commits (1)

📊 Changes

1 file changed (+0 additions, -7 deletions)

View changed files

src/Markdig/SkipLocalsInit.cs (+0 -7)

📄 Description

This PR removes the following directive:

#if NET5_0_OR_GREATER
[module: System.Runtime.CompilerServices.SkipLocalsInit]
#endif

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:

Markdown.Parse(string, MarkdownPipeline)

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: https://github.com/xoofx/markdig/issues/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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/xoofx/markdig/pull/874 **Author:** [@taublast](https://github.com/taublast) **Created:** 5/25/2025 **Status:** ❌ Closed **Base:** `master` ← **Head:** `master` --- ### 📝 Commits (1) - [`7d599e8`](https://github.com/xoofx/markdig/commit/7d599e8a074c1112f0b890fc1cfb5bd3edf2b39c) Remove SkipLocalsInit ### 📊 Changes **1 file changed** (+0 additions, -7 deletions) <details> <summary>View changed files</summary> ➖ `src/Markdig/SkipLocalsInit.cs` (+0 -7) </details> ### 📄 Description This PR removes the following directive: ```csharp #if NET5_0_OR_GREATER [module: System.Runtime.CompilerServices.SkipLocalsInit] #endif ``` 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: ```csharp Markdown.Parse(string, MarkdownPipeline) ``` 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: https://github.com/xoofx/markdig/issues/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](https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.skiplocalsinitattribute) 🚀 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 14:52:18 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#1267