---
title: decompile_assembly
description: Decompile a .NET assembly to readable C# source code or IL bytecode.
---

import { Aside, Tabs, TabItem } from "@astrojs/starlight/components";

<span class="tool-badge tool-badge-decompilation">Decompilation</span>

The primary tool for reverse-engineering .NET binaries. Recovers full C# source code from compiled `.dll` or `.exe` files. Supports targeted decompilation of individual types, compilable project generation, IL output, PDB generation, and output truncation for large assemblies.

## Parameters

| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| `assembly_path` | `string` | Yes | -- | Path to the `.dll` or `.exe` file |
| `output_dir` | `string\|null` | No | `null` | Directory to save decompiled files (returns inline if omitted) |
| `type_name` | `string\|null` | No | `null` | Fully qualified type name to decompile a single type |
| `language_version` | `string` | No | `"Latest"` | C# syntax version: `CSharp1`--`CSharp12_0`, `Preview`, `Latest` |
| `create_project` | `bool` | No | `false` | Generate a compilable `.csproj` project structure |
| `show_il_code` | `bool` | No | `false` | Output IL bytecode instead of C# |
| `remove_dead_code` | `bool` | No | `false` | Strip unreachable code paths |
| `remove_dead_stores` | `bool` | No | `false` | Strip unused variable assignments |
| `show_il_sequence_points` | `bool` | No | `false` | Include debug sequence points in IL (implies `show_il_code`) |
| `nested_directories` | `bool` | No | `false` | Organize output in namespace-based directory hierarchy |
| `generate_pdb` | `bool` | No | `false` | Generate a portable PDB file (requires `output_dir`) |
| `use_pdb_variable_names` | `bool` | No | `false` | Use original variable names from an existing PDB |
| `max_output_chars` | `int` | No | `100000` | Max inline characters. Excess is saved to a temp file. `0` disables truncation |

## Example

<Tabs>
  <TabItem label="MCP JSON">
    ```json
    {
      "tool": "decompile_assembly",
      "arguments": {
        "assembly_path": "/path/to/MyApp.dll",
        "type_name": "MyApp.Services.AuthService",
        "language_version": "Latest"
      }
    }
    ```
  </TabItem>
  <TabItem label="Python">
    ```python
    result = await client.call_tool("decompile_assembly", {
        "assembly_path": "/path/to/MyApp.dll",
        "type_name": "MyApp.Services.AuthService",
        "language_version": "Latest",
    })
    ```
  </TabItem>
</Tabs>

## Response

Returns decompiled C# source code (or IL bytecode) as formatted text. When `output_dir` is provided, files are written to disk and the response confirms the output path. If the output exceeds `max_output_chars`, the full result is saved to a temporary file and a truncated preview is returned with recovery instructions.

<Aside type="tip" title="Usage tips">
  - Use `type_name` for targeted decompilation of specific classes instead of the entire assembly.
  - Use `create_project` when you need compilable output with a `.csproj` file.
  - `generate_pdb` and `use_pdb_variable_names` require `output_dir` to be set.
  - If output is truncated, use `decompile_method` to extract individual methods.
</Aside>

## Related tools

- [decompile_method](/reference/tools/decompile-method/) -- extract a single method from a type
- [list_types](/reference/tools/list-types/) -- discover type names before targeted decompilation
- [get_assembly_info](/reference/tools/get-assembly-info/) -- quick reconnaissance before deep-diving
