BepInEx / Il2CppInterop

A tool interoperate between CoreCLR and Il2Cpp at runtime
GNU Lesser General Public License v3.0
195 stars 61 forks source link

DelegateSupport: cannot bind to the target method because its signature is not compatible #50

Closed UserUnknownFactor closed 1 year ago

UserUnknownFactor commented 1 year ago

I'm not really sure if it belongs here or in UniverseLib but for some reason UnityAction<bool> delegate (used for UnityEngine.UI.Toggle.onValueChanged.AddListener) stopped working in Unity 2020.3.38f1 while in Unity 2020.3.15f2 it worked just fine.

Here is BepInEx log:

[Warning:BepInExConfigManager] [UniverseLib] Exception invoking onInitialized callback! 
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> 
System.ArgumentException: Cannot bind to the target method because its signature is not compatible with that of the delegate type.
   at System.Delegate.CreateDelegateNoSecurityCheck(Type type, Object target, RuntimeMethodHandle method)
   at System.Reflection.Emit.DynamicMethod.CreateDelegate(Type delegateType)
   at Il2CppInterop.Runtime.DelegateSupport.<>c.<GetOrCreateNativeToManagedTrampoline>b__7_0(MethodInfo _, ValueTuple`3 tuple)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd[TArg](TKey key, Func`3 valueFactory, TArg factoryArgument)
   at Il2CppInterop.Runtime.DelegateSupport.GetOrCreateNativeToManagedTrampoline(MethodSignature signature, MethodInfo nativeMethod, MethodInfo managedMethod)
   at Il2CppInterop.Runtime.DelegateSupport.ConvertDelegate[TIl2Cpp](Delegate delegate)
   at UnityEngine.Events.UnityAction`1.op_Implicit(Action`1 )
   at UniverseLib.Il2CppExtensions.AddListener[T](UnityEvent`1 action, Action`1 listener)
   at UniverseLib.UI.UIFactory.CreateToggle(GameObject parent, String name, Toggle& toggle, Text& text, Color bgColor, Int32 checkWidth, Int32 checkHeight)
   at ConfigManager.UI.UIManager.ConstructToolbar()
   at ConfigManager.UI.UIManager.ConstructPanelContent()
   at UniverseLib.UI.Panels.PanelBase.ConstructUI()
   at UniverseLib.UI.Panels.PanelBase..ctor(UIBase owner)
   at ConfigManager.UI.UIManager..ctor(UIBase owner)
   at ConfigManager.UI.UIManager.CreateMenu()
   at ConfigManager.UI.UIManager.Init()
   at ConfigManager.ConfigManager.LateInit()
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Delegate.DynamicInvokeImpl(Object[] args)
   at System.Delegate.DynamicInvoke(Object[] args)
   at UniverseLib.Universe.InvokeOnInitialized(Action onInitialized)
UserUnknownFactor commented 1 year ago

Fixed in b663.