You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Harmony.PatchAll类型转换错误:Lethal Company模组编译失败

解决Harmony PatchAll编译错误:无法从System.Type转换为System.Reflection.Assembly

你的问题出在Harmony的PatchAll方法没有接受System.Type类型参数的重载——你传入typeof(XXX)是单个类的类型,但该方法只支持两种调用方式:无参数(扫描当前程序集所有补丁类),或者传入Assembly对象(扫描指定程序集的补丁类)。

两种正确的解决方式:

1. 批量扫描程序集内所有补丁类

如果你的所有补丁类(GokuBrackenBase、EnemyPatches等)都在当前程序集中,只需要一行代码即可完成所有补丁注入,不需要逐个类调用:

using System.Reflection;

// 替换你原来的四个PatchAll调用
this.Harmony.PatchAll(Assembly.GetExecutingAssembly());

注意:确保所有补丁类都标记了[HarmonyPatch]系列属性(比如[HarmonyPatch(typeof(目标类), "目标方法")]),否则Harmony无法识别并处理它们。

2. 单独为单个类打补丁

如果你只想给某个特定的类注入补丁,不要用PatchAll,改用CreateClassProcessor方法:

// 替换单个PatchAll(typeof(XXX))的调用
this.Harmony.CreateClassProcessor(typeof(GokuBrackenBase)).Patch();
this.Harmony.CreateClassProcessor(typeof(EnemyPatches)).Patch();
this.Harmony.CreateClassProcessor(typeof(TerminalPatches)).Patch();
this.Harmony.CreateClassProcessor(typeof(RoundManagementPatches)).Patch();

关于你尝试Assembly方法仍报错的可能原因

如果用Assembly.GetExecutingAssembly()还是出错,检查两个点:

  • 是否在代码顶部添加了using System.Reflection;引用?
  • 你的补丁类是否正确应用了Harmony的补丁属性?比如没有遗漏[HarmonyPatch],或者属性参数配置错误。

内容的提问来源于stack exchange,提问作者Noon Animates

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 09:57:11