System.DllNotFoundException' occurred in WindowsBase.dll

0

I'm trying to write a simple program in Visual Studio 2019 that will write a line in the console when a key is pressed using the Keyboard.IsKeyToggled(Key) Method. I've managed to get the code to build, but now this exception appears whenever it gets to the key detection part.

System.DllNotFoundException HResult=0x80131524 Message=Unable to load DLL 'PresentationNative_cor3.dll' or one of its dependencies: The specified module could not be found. (0x8007007E) Source=WindowsBase StackTrace: at MS.Internal.WindowsBase.NativeMethodsSetLastError.SetWindowLongPtrWndProc(HandleRef hWnd, Int32 nIndex, WndProc dwNewLong) at MS.Win32.UnsafeNativeMethods.CriticalSetWindowLong(HandleRef hWnd, Int32 nIndex, WndProc dwNewLong) at MS.Win32.HwndSubclass.HookWindowProc(IntPtr hwnd, WndProc newWndProc, IntPtr oldWndProc) at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)

I'm very new to C#, so there's likely a simple answer to this. The exception says it is unable to load DLL "PresentationNative_cor3.dll" I tried adding a reference to this DLL, but while I can find it via the file browser when I try to add it it says the DLL is unsupported.

The exception occurs at the third line:

    public static void KeyDetect()
        {
            if (Keyboard.IsKeyToggled(Key.A))
            {
                DetectLog();
            }
        }
c#
exception
dll
asked on Stack Overflow Oct 31, 2019 by ScienceKeanu • edited Oct 31, 2019 by Stephen Kennedy

2 Answers

1

The Keyboard class can be used in applications that have a window, your application is a console so you should use these instructions to listen for keyboard events in a console application.

answered on Stack Overflow Oct 31, 2019 by Claudiu Guiman
1

You can try the following code to detect the key in console.

static void Main(string[] args)
        {
            KeyDetect();
            Console.ReadKey();
        }

        public static void KeyDetect()
        {
            ConsoleKey key;
            key = Console.ReadKey(true).Key;
            if (key==ConsoleKey.A)
            {
                Console.WriteLine("You are pressing A");
            }
        }
answered on Stack Overflow Nov 1, 2019 by Jack J Jun - MSFT

User contributions licensed under CC BY-SA 3.0