# IL2CPP 错误：System.MissingMethodException：找不到方法：'Void UnityEngine.UI.Image::set_sprite(UnityEngine.Sprite)'

- **ID:** `unity/il2cpp-missing-method`
- **领域:** unity
- **类别:** build_error
- **验证级别:** ai_generated
- **修复率:** 78%

## 根因

IL2CPP 代码剥离删除了通过反射或链接器不可见的代码路径引用的方法。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 2021.3.30f1 | active | — | — |
| 2022.3.10f1 | active | — | — |
| 6000.0.0b12 | active | — | — |

## 解决方案

1. ```
   Add [Preserve] attribute to the specific method: `[Preserve] private void SetSpriteMethod(Sprite s) { image.sprite = s; }`
   ```
2. ```
   Create a link.xml file in Assets/Plugins with: <linker><assembly fullname="UnityEngine.UI"><type fullname="UnityEngine.UI.Image" preserve="all"/></assembly></linker>
   ```
3. ```
   Use `#if !UNITY_EDITOR` to force a direct call to the method in a startup script so IL2CPP sees it
   ```

## 无效尝试

- **** — Preserve only works on specific methods or fields, not entire files; may not cover all reflection paths. (65% 失败率)
- **** — Disabling stripping increases build size significantly and may hide but not fix the underlying reflection issue. (40% 失败率)
- **** — The issue is in IL2CPP code generation, not asset import; rebuild doesn't change stripping behavior. (90% 失败率)
