egametang/ET · error · Exception
none of methods targetMethod or replacementMethod can be nul
Error message
none of methods targetMethod or replacementMethod can be null
What it means
Thrown by MethodHook.DoInstall() when either targetMethod or replacementMethod is null. DoInstall is the core hook-installation entry point; it needs valid MethodInfo objects for both the original method (to patch) and the replacement method (to jump to). A null means the caller failed to resolve one via reflection before constructing the hook.
Source
Thrown at Packages/cn.etetet.hybridclr/Scripts/Editor/Share/3rds/UnityHook/MethodHook.cs:155
isPlayModeHook = Application.isPlaying;
}
public void Uninstall()
{
if (!isHooked)
return;
_codePatcher.RemovePatch();
isHooked = false;
HookPool.RemoveHooker(targetMethod);
}
#region private
private void DoInstall()
{
if (targetMethod == null || replacementMethod == null)
throw new Exception("none of methods targetMethod or replacementMethod can be null");
HookPool.AddHook(targetMethod, this);
if (_codePatcher == null)
{
if (GetFunctionAddr())
{
#if ENABLE_HOOK_DEBUG
UnityEngine.Debug.Log($"Original [{targetMethod.DeclaringType.Name}.{targetMethod.Name}]: {HookUtils.HexToString(_targetPtr.ToPointer(), 64, -16)}");
UnityEngine.Debug.Log($"Original [{replacementMethod.DeclaringType.Name}.{replacementMethod.Name}]: {HookUtils.HexToString(_replacementPtr.ToPointer(), 64, -16)}");
if(proxyMethod != null)
UnityEngine.Debug.Log($"Original [{proxyMethod.DeclaringType.Name}.{proxyMethod.Name}]: {HookUtils.HexToString(_proxyPtr.ToPointer(), 64, -16)}");
#endif
CreateCodePatcher();
_codePatcher.ApplyPatch();
#if ENABLE_HOOK_DEBUGView on GitHub (pinned to 5cab01f7a8)
Solutions
- Log both targetMethod and replacementMethod before calling Install() to identify which is null.
- Fix the reflection lookup: verify the method name, declaring type, binding flags, and parameter signature match exactly.
- If the method was renamed in an update, update the hook code to use the new name.
- Ensure the assembly containing the target type is loaded before constructing the MethodHook — call Assembly.Load or trigger type resolution first.
Example fix
// before
var hook = new MethodHook(targetMethod, replacementMethod);
hook.Install(); // throws if targetMethod is null
// after — validate before installing
if (targetMethod == null)
Debug.LogError($"Target method not found on type {targetType.FullName}");
if (replacementMethod == null)
Debug.LogError($"Replacement method not found on type {replacementType.FullName}");
if (targetMethod != null && replacementMethod != null)
{
var hook = new MethodHook(targetMethod, replacementMethod);
hook.Install();
} Defensive patterns
Strategy: validation
Validate before calling
if (targetMethod == null)
Debug.LogError($"Target method not found. Check type '{targetTypeName}' and method name '{targetMethodName}' with correct BindingFlags.");
if (replacementMethod == null)
Debug.LogError($"Replacement method not found. Check type '{replacementTypeName}' and method name '{replacementMethodName}'.");
if (targetMethod == null || replacementMethod == null)
return; // do not proceed to Install() Type guard
static bool IsHookable(MethodInfo target, MethodInfo replacement)
{
return target != null && replacement != null && !target.IsAbstract;
} Try / catch
try
{
hook.Install();
}
catch (Exception ex) when (ex.Message.Contains("none of methods targetMethod or replacementMethod can be null"))
{
Debug.LogError($"Hook installation failed: targetMethod={targetMethod?.Name ?? "null"}, " +
$"replacementMethod={replacementMethod?.Name ?? "null"}. " +
"Verify reflection lookups (method name, BindingFlags, overload signature).");
} Prevention
- Always null-check MethodInfo results from GetMethod before constructing a MethodHook.
- Use precise BindingFlags (Public/NonPublic, Static/Instance) matching the target method.
- For overloaded methods, use the GetMethod overload that accepts parameter types to avoid ambiguity.
- Ensure the declaring type's assembly is loaded before reflection.
When it happens
Trigger: Calling Install() on a MethodHook instance where the targetMethod or replacementMethod field is null. This typically stems from a reflection lookup (GetMethod, Type.GetMethod) that returned null — e.g. the method name was misspelled, the binding flags were wrong, the method is overloaded and the signature didn't match, or the declaring type wasn't loaded.
Common situations: The target method was renamed or removed in a library update; BindingFlags mismatch when calling GetMethod on a non-public or static method; an overloaded method where the overload resolution via reflection returned null; the assembly containing the target type wasn't loaded yet at hook construction time.
Related errors
- MethodHook:targetMethod and replacementMethod and proxyMetho
- WRANING: you can not hook abstract method [{methodName}]
- address offset of target and replace must less than ((1 << 2
- address offset of target and replace must larger than ((1 <<
- address offset of target and replace must less than (1 << 26
AI-assisted analysis of egametang/ET@5cab01f7a8 (2026-08-13).
Data as JSON: /api/errors/507af33f76cccfab.
Report an issue: GitHub.