Memory Safety v2 Tracking Issue
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Description
Memory safety is a critical characteristic for Cloud and AI scenaros. We are making the definition of unsafe code more strict (more patterns are unsafe), making the use of unsafe code more viral (propogation), and making it easier to audit dependencies.
See [Improving C# Memory Safety](https://devblogs.microsoft.com/dotnet/improving-csharp-memory-safety/) for a higher-level view.
## Current backlog
- [ ] [C# Unsafe Evolution](https://github.com/dotnet/csharplang/issues/9704)
- [x] [Initial Implementation](https://github.com/dotnet/roslyn/pull/82547)
- [ ] [Test Plan](https://github.com/dotnet/roslyn/issues/81207)
- [ ] [Follow ups](https://github.com/dotnet/roslyn/issues/82546)
- [ ] [Unsafe Evolution Attributes](https://github.com/dotnet/runtime/issues/125134)
- [ ] Library annotations
- https://github.com/dotnet/runtime/issues/125145
- https://github.com/dotnet/runtime/pull/125196
- [ ] Library source generators/analyzers
- [ ] [LibraryImport source generator should generate unsafe code by default](https://github.com/dotnet/runtime/issues/125801)
## Out of scope
The following components are out of scope for the project.
- Reflection
## Context
We expect that user requirements will increasingly favor memory safe languages as Cloud and AI domains evolve. C# is already a memory safe language, however, we can do more to increase user confidence. Our project has significant overlap with [Swift 6.2](https://www.swift.org/blog/swift-6.2-released/#safe-systems-programming). It also has overlap with Rust behavior.
A related effort is [reducing unsafe code](https://github.com/dotnet/runtime/issues?q=state%3Aopen%20label%3Areduce-unsafe) in the codebase. This includes: adopting newer safe patterns that deliver acceptable (sometimes better) performance relative to and older unsafe pattern, removing unsafe code where it is needed/warranted, and creating new safe patterns (often in the JIT) to apply.
Learn more:
- [Memory Safety in .NET](https://github.com/dotnet/designs/blob/main/accepted/2025/memory-safety/memory-safety.md)
- [Annotating members as unsafe](https://github.com/dotnet/designs/blob/main/accepted/2025/memory-safety/caller-unsafe.md)
- [SDK Unsafe Adoption](https://github.com/dotnet/designs/blob/main/accepted/2025/memory-safety/sdk-memory-safety-enforcement.md)
- [.NET 9 Unsafe Study](https://github.com/dotnet/runtime/issues/94941)
- [Enumerating type safety guarantees in MemoryMarshal and friends](https://github.com/dotnet/runtime/issues/41418)
- [Unsafe code best practices](https://learn.microsoft.com/dotnet/standard/unsafe-code/best-practices)
Contributor guide
Assessment
This issue has not been assessed yet.