Skip to content

Conversation

EgorBo
Copy link
Member

@EgorBo EgorBo commented Sep 16, 2025

Summary

The document contains best practices when dealing with Unsafe code in .NET (focusing on C#), a set of common unreliable patterns and how to avoid them. Some background on why we do this is described here: dotnet/designs#341

We were using https://learn.microsoft.com/en-us/dotnet/standard/native-interop/best-practices as an inspiration for this doc.

cc @jkotas @richlander


Internal previews

📄 File 🔗 Preview link
docs/navigate/advanced-programming/toc.yml docs/navigate/advanced-programming/toc
docs/standard/unsafe-code/best-practices.md docs/standard/unsafe-code/best-practices

Copy link

@hamarb123 hamarb123 left a comment

Choose a reason for hiding this comment

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

Other than the comments I made on discord, looks good to me :)

@EgorBo
Copy link
Member Author

EgorBo commented Sep 18, 2025

@jkotas anything else here from our side?

@jkotas
Copy link
Member

jkotas commented Sep 18, 2025

This needs to be reviewed and signed off by the doc maintainers before merging. It looks good to me otherwise.

EgorBo and others added 5 commits September 18, 2025 22:47
Co-authored-by: Genevieve Warren <[email protected]>
2) Replace ```cs with ```csharp
3) Add links to .NET Memory Model
@EgorBo
Copy link
Member Author

EgorBo commented Sep 18, 2025

@gewarren thank you so much for the corrections! I learned a lot 🙂 I believe, I've addressed all of your requests.

Copy link
Contributor

@gewarren gewarren left a comment

Choose a reason for hiding this comment

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

A few xref fixes. I'll commit these.

@EgorBo
Copy link
Member Author

EgorBo commented Sep 18, 2025

@gewarren ah, thanks, I already fixed them locally (just pushed) via that extension that you recommended

@gewarren
Copy link
Contributor

@gewarren ah, thanks, I already fixed them locally (just pushed) via that extension that you recommended

Nice, that was my hackathon project last year :)

@EgorBo
Copy link
Member Author

EgorBo commented Sep 18, 2025

@gewarren ah, thanks, I already fixed them locally (just pushed) via that extension that you recommended

Nice, that was my hackathon project last year :)

Awesome! It does look handy.

Regarding the PR, who typically merges the PRs?

@gewarren
Copy link
Contributor

gewarren commented Sep 18, 2025

Regarding the PR, who typically merges the PRs?

Me or one of the other content devs (or you if you have write perms). I'll merge it now. Thanks for adding this doc!

@gewarren gewarren merged commit 63edbd5 into main Sep 18, 2025
10 checks passed
@gewarren gewarren deleted the unsafe-code-guidelines branch September 18, 2025 22:30
@richlander
Copy link
Member

Thanks much!

@Frulfump
Copy link

Here's the live link for anyone like me who was looking for it
https://learn.microsoft.com/en-us/dotnet/standard/unsafe-code/best-practices

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants