Skip to content

Add unsafe-code/best-practices.md - #48557

Merged
gewarren merged 14 commits into
mainfrom
unsafe-code-guidelines
Sep 18, 2025
Merged

Add unsafe-code/best-practices.md#48557
gewarren merged 14 commits into
mainfrom
unsafe-code-guidelines

Conversation

@EgorBo

@EgorBo EgorBo commented Sep 16, 2025

Copy link
Copy Markdown
Member

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

Comment thread docs/standard/unsafe-code/best-practices.md Outdated
Comment thread docs/standard/unsafe-code/best-practices.md Outdated
Comment thread docs/standard/unsafe-code/best-practices.md Outdated

@hamarb123 hamarb123 left a comment

Copy link
Copy Markdown

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 :)

Comment thread docs/standard/unsafe-code/best-practices.md Outdated
EgorBo and others added 3 commits September 17, 2025 16:07
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
@EgorBo

EgorBo commented Sep 18, 2025

Copy link
Copy Markdown
Member Author

@jkotas anything else here from our side?

@jkotas

jkotas commented Sep 18, 2025

Copy link
Copy Markdown
Member

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

Comment thread docs/standard/unsafe-code/best-practices.md
Comment thread docs/standard/unsafe-code/best-practices.md Outdated
Comment thread docs/standard/unsafe-code/best-practices.md Outdated
Comment thread docs/standard/unsafe-code/best-practices.md Outdated
Comment thread docs/standard/unsafe-code/best-practices.md Outdated
Comment thread docs/standard/unsafe-code/best-practices.md Outdated
Comment thread docs/standard/unsafe-code/best-practices.md Outdated
Comment thread docs/standard/unsafe-code/best-practices.md Outdated
Comment thread docs/standard/unsafe-code/best-practices.md Outdated
Comment thread docs/standard/unsafe-code/best-practices.md Outdated
EgorBo and others added 5 commits September 18, 2025 22:47
Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com>
2) Replace ```cs with ```csharp
3) Add links to .NET Memory Model
@EgorBo

EgorBo commented Sep 18, 2025

Copy link
Copy Markdown
Member Author

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

@gewarren gewarren left a comment

Copy link
Copy Markdown
Collaborator

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.

Comment thread docs/standard/unsafe-code/best-practices.md Outdated
Comment thread docs/standard/unsafe-code/best-practices.md Outdated
Comment thread docs/standard/unsafe-code/best-practices.md Outdated
@EgorBo

EgorBo commented Sep 18, 2025

Copy link
Copy Markdown
Member Author

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

@gewarren

Copy link
Copy Markdown
Collaborator

@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

EgorBo commented Sep 18, 2025

Copy link
Copy Markdown
Member Author

@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

gewarren commented Sep 18, 2025

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
Member

Thanks much!

@Frulfump

Copy link
Copy Markdown

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