Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
.NET Day 2019 - Abusing the C# compiler by Fili...
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
.NET Day
May 28, 2019
Technology
130
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
.NET Day 2019 - Abusing the C# compiler by Filip Wojcieszyn
.NET Day
May 28, 2019
More Decks by .NET Day
See All by .NET Day
.NET Day 2025: How to Lie with AI: Understanding Bias, Ethics, and the Hidden Risks in Machine Learning
dotnetday
0
33
.NET Day 2025: Most Expensive Design Mistakes (Ever) and how to avoid them
dotnetday
0
39
.NET Day 2025: Turbocharged: Writing High-Performance C# and .NET Code
dotnetday
0
52
.NET Day 2025: Developing ASP.NET Core Microservices with Dapr: A practical guide
dotnetday
0
43
.NET Day 2025: Enhancing Legal Document Analysis with Reflection Agents, Semantic Kernel, and Azure AI Search
dotnetday
0
33
.NET Day 2025: Future-Proof Your Blazor Apps with bUnit
dotnetday
0
28
.NET Day 2025: .NET Core Testing: pushing the limits
dotnetday
0
50
.NET Day 2025: The best ways to use the latest OpenAPI features in .NET 9!
dotnetday
0
39
.NET Day 2025: Supercharged Search with Semantic Search and Vector Embeddings
dotnetday
0
38
Other Decks in Technology
See All in Technology
自分が詳しくない領域でAIを使う #プロヒス2026
konifar
11
2.8k
20260619 私の日常業務での生成 AI 活用
masaruogura
1
230
FPGAの開発コンペでZephyrを使ってみた
iotengineer22
0
110
現地で盛り上がった WWDC26 Keynote
zozotech
PRO
1
260
MUSUBI 田中裕一『AIと共に行う「しごとのリデザイン」- スモールバックオフィス編』AI Ops Lab #4
musubi
0
240
AWS Security Hub CSPMの成功・失敗体験
cmusudakeisuke
0
200
Oracle AI Database@Azure:サービス概要のご紹介
oracle4engineer
PRO
6
2k
Agent Skills設計で柔軟性と硬さのバランスが難しい話
nassy20
0
140
気軽に使える"情報のハブ"としてのNotion活用 〜フロー情報の集積点 と、 Claude Code × Notion AI〜
syucream
1
150
手塩にかけりゃいいってもんじゃない
ming_ayami
0
610
2026TECHFRESH畢業分享會 - AI 時代的人生存檔點
line_developers_tw
PRO
0
1.3k
2026年6月23日 Syncable Tech + Start Python Club にて
hamukazu
0
140
Featured
See All Featured
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
440
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
Docker and Python
trallard
47
3.9k
Google's AI Overviews - The New Search
badams
0
1k
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Leo the Paperboy
mayatellez
7
1.8k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
860
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.9k
Between Models and Reality
mayunak
4
340
Designing Experiences People Love
moore
143
24k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
370
Transcript
Abusing the C# Abusing the C# Compiler Compiler for fun
and no pro t for fun and no pro t
Filip W Filip W a random guy from the internet
• • strathweb.com @ lip_woj github.com/ lipw
None
What will we What will we learn? learn?
Nothing.
We will however see, that it doesn't take a lot
to violate the rules of C#.
C# Compiler C# Compiler
None
“ Compiler is the guardian of the integrity of the
language.
C# 6 Draft Spec Reading C# 6 Draft Spec Reading
High level C# building blocks High level C# building blocks
C# Languague Speci cation ECMA Standard, ~500 pages ⚙ Roslyn Compiler compiles C# code to Common Intermediate Language Tooling powered by the C# Compiler CLR / CoreCLR compiles CIL to machine code
Can you trust the Can you trust the compiler? compiler?
- Mads Torgersen, C# Lead Designer “ Customers will depend
on the new compiler behaving exactly the same way as the old one. Writing a new compiler for C# means trying to match the old compiler bug-for-bug.
Invalid C#, compiler error Invalid C#, compiler error static class
Foo {} class Bar { // error CS0722: 'Foo': static types cannot be used as return types Foo GetFoo() => null; }
Invalid C#, no compiler error Invalid C#, no compiler error
static class Foo {} interface IBar { // compiles fine Foo GetFoo(); }
Can the compiler produce a program that won't work? Yes
Let's assume that the code is 100% error free. Still
yes
Language Spec Compiler Runtime
Can the runtime allow you to violate the C# language
speci cation? Yes
Language Spec Compiler Runtime
- Eric Lippert “ A common technique (...) is to
have the compiler “lower” from high-level language features to low-level language features in the same language.
C# using block C# using block using(new C()) { //
do stuff }
Emitted IL Emitted IL IL_0000: nop IL_0001: newobj instance void
C::.ctor() IL_0006: stloc.0 .try { IL_0007: nop IL_0008: nop IL_0009: leave.s IL_0016 } // end .try finally { // sequence point: hidden IL_000b: ldloc.0 IL_000c: brfalse.s IL_0015 IL_000e: ldloc.0 IL_000f: callvirt instance void [mscorlib]System.IDisposable::Dispose() IL_0014: nop // sequence point: hidden IL_0015: endfinally } // end handler
“ This method terminates a process without running any active
try/ nally blocks or nalizers. - Environment.FailFast(...)
So far we have managed to So far we have
managed to ✅ Create an instance without calling a constructor ✅ Bypass a ' nally' clause ✅ Create an instance of an open generic
Can the compiler produce code that doesn’t behave as expected?
Yes
Language Spec Compiler Runtime
How badly can you abuse the language and the compiler?
Very badly
Language Spec Compiler Runtime
Thank you Thank you See you next year! lipw.github.io/dotnetday-zurich-2019 github.com/
lipw/2019-switzerland- netday-demos