TL;DR

Microsoft is developing a significant update to C# memory safety, redesigning the unsafe keyword to make safety contracts explicit. The new model will be previewed in .NET 11 and released in .NET 12, aiming to enhance code security and reviewability.

Microsoft is actively developing a new memory safety model for C# that will overhaul the way unsafe code is handled, making safety contracts more explicit and enforceable by the compiler. This update aims to improve security and code review processes in C# applications.

The new model redefines the unsafe keyword in C# to serve as a safety contract rather than just a syntax marker. It expands from marking pointers to encompassing any code interacting with memory in ways the compiler cannot verify as safe. This change will be introduced as a preview in .NET 11 and become a production feature in .NET 12, initially opt-in, with potential to become the default. The early implementation has already landed in the main branch of the compiler. Historically, C#’s unsafe context has allowed developers to access pointers and unmanaged memory, which can lead to undefined behavior if misused. The redesigned unsafe keyword will enforce stricter review and clearer boundaries, aligning more closely with models used in Rust and Swift. This effort reflects industry-wide emphasis on memory safety, especially as AI-assisted code generation increases the scale of software production, raising security concerns. The new model aims to make unsafe code more transparent, reviewable, and safer, reducing risks of memory-related vulnerabilities.

Why It Matters

This development is significant because it enhances C#’s ability to prevent memory safety issues, which are a primary source of security vulnerabilities and bugs in software. By making safety contracts explicit and enforceable, it improves code quality, security, and maintainability. It also aligns C# with other languages like Rust and Swift that have stricter safety semantics. As software systems become more complex and automated code generation grows, these improvements are vital for industry standards and security compliance.

Sit. Stay. Remember Nothing. Password Tracker: Password Organizer with Notes, Password Book with Alphabetical Tabs, 6x9 Password Keeper, Password Book for Seniors, 132 pages for passwords and notes

Sit. Stay. Remember Nothing. Password Tracker: Password Organizer with Notes, Password Book with Alphabetical Tabs, 6×9 Password Keeper, Password Book for Seniors, 132 pages for passwords and notes

As an affiliate, we earn on qualifying purchases.

As an affiliate, we earn on qualifying purchases.

Background

Since its introduction in C# 1.0, the unsafe keyword has been used to allow developers to work with pointers and unmanaged memory, primarily for interoperability and performance. Learn more about memory management. Over time, other languages like Rust and Swift adopted stricter, propagation-oriented semantics for unsafe code, emphasizing safety contracts. Microsoft’s ongoing efforts aim to modernize C#’s approach, aligning it with these models. The upcoming changes are part of a broader initiative to improve safety in the .NET ecosystem, especially as industry and government prioritize memory safety and security. The early compiler modifications have already been integrated, indicating active progress toward these goals.

“The new safety model will make safety contracts in unsafe code explicit and enforceable, improving security and reviewability.”

— Microsoft developer team

“Aligning C# unsafe semantics with Rust’s propagation model will help developers better understand and manage unsafe operations.”

— C# language architect

Elevator Debugging Tools TCM Manager Copy Program Modify Parameters

Elevator Debugging Tools TCM Manager Copy Program Modify Parameters

Elevator Debugging Tools TCM Manager Copy Program Modify Parameters

As an affiliate, we earn on qualifying purchases.

As an affiliate, we earn on qualifying purchases.

What Remains Unclear

It is not yet clear how widely adopted the new model will be in early releases or whether it will become the default in future versions. Details about tooling updates and developer migration strategies are still emerging.

Effective .NET Memory Management: Build memory-efficient cross-platform applications using .NET Core

Effective .NET Memory Management: Build memory-efficient cross-platform applications using .NET Core

As an affiliate, we earn on qualifying purchases.

As an affiliate, we earn on qualifying purchases.

What’s Next

Microsoft plans to release the new safety model as a preview in .NET 11, with full support in .NET 12. Developers and teams are encouraged to experiment with the preview and provide feedback. Further updates on tooling, documentation, and best practices are expected ahead of the full release.

POS Software – All in One Retail Point of Sale Software - Credit Card Processing – Store Management Features, 90 Days Money Back, Free Updates/e-mail Support/video Tutorials

POS Software – All in One Retail Point of Sale Software – Credit Card Processing – Store Management Features, 90 Days Money Back, Free Updates/e-mail Support/video Tutorials

Affordable POS Software

As an affiliate, we earn on qualifying purchases.

As an affiliate, we earn on qualifying purchases.

Key Questions

What is changing about the unsafe keyword in C#?

The unsafe keyword will be redesigned to serve as a safety contract, making the obligations and boundaries of unsafe code explicit and enforceable by the compiler, rather than just a syntax marker.

When will the new memory safety model be available?

The preview will be available in .NET 11, with the full release planned for .NET 12.

Will this change affect existing unsafe code?

Existing unsafe code will continue to work, but developers may need to update code to adhere to the new safety contracts and review guidelines introduced in the new model.

Why is this update important for software security?

By making safety boundaries explicit and enforceable, the update reduces the risk of memory-related vulnerabilities, which are a common source of security bugs and exploits.

Source: Hacker News

You May Also Like

CRISPR tech selectively shreds cancer cells, including “undruggable” cancers

New CRISPR-based method selectively destroys cancer cells, including difficult-to-treat types, offering potential for advanced cancer therapies.

WWDC 2026: Apple is Folding

Apple reveals a foldable iPhone, the iPhone Ultra, with a 7.8-inch display, supporting app resizing and flexible design, set for release in July 2026.

PgDog is funded and coming to a database near you

PgDog, a new open-source Postgres proxy designed for horizontal scaling, has received funding and is now available for deployment across various environments.

Age verification tech could put children at greater risk, says think tank

A think tank warns that proposed mandatory online age verification may expose children to greater risks, including privacy breaches and exclusion.