articles

.NET framework‑managed code generations

I asked M365 Copilot for a list of framework‑managed code generations that .NET is capable of. The following is what M365 Copilot responded

Below is a comprehensive, categorized list of framework‑managed code generation mechanisms that .NET is capable of, with clear distinctions about when the code is generated (compile time vs runtime), how it is generated, and who controls it (framework vs developer).

This list focuses on code generation performed by the .NET runtime or framework infrastructure itself, not user-authored generators.


Framework‑Managed Code Generation in .NET

1. XML Serialization (XmlSerializer)

Type: Runtime and Compile‑time
Scope: Infrastructure-level

What is generated

When

Mechanism

Notes

True code generator


2. Regular Expressions (Regex)

Type: Runtime or Compile‑time
Scope: Infrastructure-level

What is generated

When

Mechanism

Notes

True code generator


3. ASP.NET / ASP.NET Core View Compilation (Razor)

Type: Compile‑time and/or Runtime
Scope: Web framework

What is generated

When

Mechanism

Notes

True code generator


4. Dynamic Proxies (Castle, DispatchProxy, WCF proxies)

Type: Runtime
Scope: Framework + library infrastructure

What is generated

When

Mechanism

Examples

True code generator


5. Expression Tree Compilation

Type: Runtime
Scope: Runtime infrastructure

What is generated

When

Mechanism

Notes

True code generator


6. LINQ Providers (e.g., LINQ to Objects, EF Core)

Type: Runtime
Scope: Hybrid (framework + provider)

What is generated

Mechanism

Notes

Often code generation (depending on provider)


7. COM Interop / Runtime Callable Wrappers

Type: Runtime / Build-time
Scope: Interop infrastructure

What is generated

Mechanism

Notes

True code generator


8. P/Invoke and Interop Marshalling Stubs

Type: Runtime (JIT) and Compile-time optimization
Scope: Runtime infrastructure

What is generated

Mechanism

Notes

Code generation (low-level, opaque)


9. ASP.NET Routing, Middleware, and Endpoints

Type: Compile‑time (modern)
Scope: Web framework

Example

What is generated

Notes

Compile-time framework-managed generation


10. Entity Framework Core (Compiled Models & Queries)

Type: Runtime and Compile‑time
Scope: ORM infrastructure

What is generated

Mechanism

Notes

True code generator


11. Binary / Serialization Infrastructure (Formatter-based)

Type: Runtime
Scope: Serialization infrastructure (legacy)

Examples

Mechanism

True code generator (legacy, discouraged)


Important Non‑Examples (Not Code Generation)

To avoid confusion, these are not code generators:

Feature Why
C# Generics JIT specialization, not generation
Interfaces No emitted implementations
Reflection No code emission
Attributes Metadata only
JIT compilation itself Compilation ≠ generation

Mental Model: How to Classify .NET Code Generation

Code generation if ALL are true:

  1. New executable code is produced
  2. Code did not exist as source beforehand
  3. Generated programmatically
  4. Loaded or executed by the runtime

One‑paragraph summary

.NET supports extensive framework‑managed code generation across serialization, regex, web frameworks, interop, LINQ, ORM, proxies, and expression trees—using both runtime IL emission and compile‑time source generation. These mechanisms exist to replace slow reflection with specialized code while remaining mostly invisible to the developer.

If you want next, I can:

Just say which direction you’d like to go.