Bringing Rust memory management to C#


I’ve become interested in Rust, a memory and thread safe systems programming language. However, I dislike having to learn another new syntax and Rust lacks some of the concepts (such as class inheritance) which are familiar to me.

So I was wondering, would it be possible for Microsoft to port some of the most important Rust concepts, memory and thread safety through borrowing etc. to C#?

Or do we need another .NET language family member which doesn’t have garbage collection but instead offers support for the Rust concepts? Also an AOT (ahead of time) compiler would be nice so this language could be used to built operating systems and low level programing.

  • C# is already memory safe.
  • The garbage collector is an integral part of .Net, so I think it doesn’t make sense to have a .Net language without GC.
  • AOT compilers for .Net already exist. One is part of Mono, another one is CoreRT.

In general, I think that mashing two languages together the way you’re suggesting is not a good idea. The ways a language solves various problems are often specific to that programming language, so what works in one language probably won’t work well in a different language.

On the other hand, a safe, system programming language based on C# is an interesting idea. You might want to read about the Midori project, which was an attempt to create a whole operating system based on a variant of C# for how that might look like.


AFAIK Midori didn’t use a separate C# language family member, but built an OS in C# running on a VM on top of a small C bootloader.

Yes, C# is memory safe, but not deterministic because of the garbage collection, and therefore not useful for systems programming.

And it turns out that memory safety and thread safety are two sides of the same coin.

In general, I’m baffled why Microsoft hasn’t built a C# AOT compiler and required frameworks to replace their C++ infrastructure. Many of their products would benefit enormously (qualitatively) if they were (re)written in C#.


I don’t really know how rust work. But if you really thinks some thinks is interesting I encourage you to see if the issue wasn’t open on GitHub. And open it if not.

I don’t understand. As @svick say the new c# compiler is in C# and have a AOT Scenario possible ( && Am I missing somethinks?.


There is a .NET AOT compiler somewhere, but it can only be used for UWP apps, which isn’t terribly useful in itself. I’d want a AOT compiler that works with everything: WinForms, ASP.NET, WPF, the whole shabang.


I’ve even conjured up a name for this new .NET member: Knife# :slight_smile:

.NET Foundation Website | Blog | Projects | Code of Conduct