Hellooooo,
I have a problem trying to access the System.Windows.Input.Keyboard class to be able to use any buttons ingame (and not just GTA’s controls).
Code Snippet
using System;
using System.Threading.Tasks;
using CitizenFX.Core;
using System.Windows.Input;
namespace InputManager
{
public class InputManager : BaseScript
{
public InputManager() {
Tick += OnTick;
}
private async Task OnTick() {
await Delay(0);
if (Keyboard.IsKeyDown(Key.Return)) {
Debug.WriteLine("TEST");
}
}
}
}
Error Stacktrace
[ 679140] [ GTAProcess] MainThrd/ Exception thrown by a task: System.AggregateException: One or more errors occurred. ---> System.BadImageFormatException: Error verifying InputManager.InputManager/<OnTick>d__1:MoveNext (): Cannot load method from token 0x0a000021 for call at 0x006d
[ 679156] [ GTAProcess] MainThrd/ at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine] (TStateMachine& stateMachine) [0x0002c] in <74fbbe963b7e417b8d715b858c5c584f>:0
[ 679156] [ GTAProcess] MainThrd/ at InputManager.InputManager.OnTick () [0x0001f] in <2d7ba2b50ee8452a86f250601200c263>:0
[ 679171] [ GTAProcess] MainThrd/ at CitizenFX.Core.BaseScript+<>c__DisplayClass34_1.<ScheduleTick>b__1 () [0x00030] in C:\gl\builds\edf06b9b\0\cfx\fivem\code\client\clrcore\BaseScript.cs:166
[ 679187] [ GTAProcess] MainThrd/ at System.Threading.Tasks.Task`1[TResult].InnerInvoke () [0x0000f] in <74fbbe963b7e417b8d715b858c5c584f>:0
[ 679187] [ GTAProcess] MainThrd/ at System.Threading.Tasks.Task.Execute () [0x00010] in <74fbbe963b7e417b8d715b858c5c584f>:0
[ 679187] [ GTAProcess] MainThrd/ --- End of inner exception stack trace ---
[ 679187] [ GTAProcess] MainThrd/ ---> (Inner Exception #0) System.BadImageFormatException: Error verifying InputManager.InputManager/<OnTick>d__1:MoveNext (): Cannot load method from token 0x0a000021 for call at 0x006d
[ 679203] [ GTAProcess] MainThrd/ at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine] (TStateMachine& stateMachine) [0x0002c] in <74fbbe963b7e417b8d715b858c5c584f>:0
[ 679203] [ GTAProcess] MainThrd/ at InputManager.InputManager.OnTick () [0x0001f] in <2d7ba2b50ee8452a86f250601200c263>:0
[ 679203] [ GTAProcess] MainThrd/ at CitizenFX.Core.BaseScript+<>c__DisplayClass34_1.<ScheduleTick>b__1 () [0x00030] in C:\gl\builds\edf06b9b\0\cfx\fivem\code\client\clrcore\BaseScript.cs:166
[ 679203] [ GTAProcess] MainThrd/ at System.Threading.Tasks.Task`1[TResult].InnerInvoke () [0x0000f] in <74fbbe963b7e417b8d715b858c5c584f>:0
[ 679203] [ GTAProcess] MainThrd/ at System.Threading.Tasks.Task.Execute () [0x00010] in <74fbbe963b7e417b8d715b858c5c584f>:0 <---
[ 679218] [ GTAProcess] MainThrd/
[ 679218] [ GTAProcess] MainThrd/ Failed to run a tick for InputManager: System.BadImageFormatException: Error verifying InputManager.InputManager/<OnTick>d__1:MoveNext (): Cannot load method from token 0x0a000021 for call at 0x006d
[ 679218] [ GTAProcess] MainThrd/ at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine] (TStateMachine& stateMachine) [0x0002c] in <74fbbe963b7e417b8d715b858c5c584f>:0
[ 679218] [ GTAProcess] MainThrd/ at InputManager.InputManager.OnTick () [0x0001f] in <2d7ba2b50ee8452a86f250601200c263>:0
[ 679218] [ GTAProcess] MainThrd/ at CitizenFX.Core.BaseScript+<>c__DisplayClass34_1.<ScheduleTick>b__1 () [0x00030] in C:\gl\builds\edf06b9b\0\cfx\fivem\code\client\clrcore\BaseScript.cs:166
[ 679218] [ GTAProcess] MainThrd/ at System.Threading.Tasks.Task`1[TResult].InnerInvoke () [0x0000f] in <74fbbe963b7e417b8d715b858c5c584f>:0
[ 679218] [ GTAProcess] MainThrd/ at System.Threading.Tasks.Task.Execute () [0x00010] in <74fbbe963b7e417b8d715b858c5c584f>:0
Any idea on what is causing that error? I even tried including WindowsBase.dll just to make sure it isn’t missing anything.