# IL2CPP 错误：System.IO.DirectoryNotFoundException：找不到路径 'C:\Build\Temp\StagingArea\Data\Managed\System.dll' 的一部分

- **ID:** `unity/il2cpp-error-marshal-directorynotfound`
- **领域:** unity
- **类别:** build_error
- **验证级别:** ai_generated
- **修复率:** 75%

## 根因

IL2CPP 构建过程在暂存区找不到所需的托管程序集（例如 System.dll），通常是由于构建缓存不完整或缺少 .NET 后端文件。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Unity 2022.3.30f1 | active | — | — |
| Unity 2023.2.5f1 | active | — | — |
| Unity 6000.0.0a20 | active | — | — |

## 解决方案

1. ```
   Delete the 'Library' and 'Temp' folders in the project directory, then rebuild from scratch. This clears the corrupted build cache.
   ```
2. ```
   In Project Settings > Player > Configuration, set 'Scripting Backend' to 'IL2CPP' and 'Api Compatibility Level' to '.NET Standard 2.1' (or '.NET Framework' if available). Then perform a clean build via Build Settings > Clean Build.
   ```

## 无效尝试

- **** — The issue is a corrupted build cache, not missing Unity components. (80% 失败率)
- **** — The staging area is regenerated each build; manual copies are overwritten or cause version mismatches. (95% 失败率)
- **** — This avoids the error but changes the runtime behavior and may not be acceptable for platforms requiring IL2CPP (e.g., iOS, WebGL). (50% 失败率)
