Search code examples
wpfxamlparsingexceptionunhandled

WPF Xaml Parse Exception unhandled


An unhandled exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll

Additional information: 'The invocation of the constructor on type 'JustSnap.MainWindow' that matches the specified binding constraints threw an exception.' Line number '3' and line position '9'.

If I click view details:

{System.ComponentModel.Win32Exception (0x80004005): The specified module could not be found
   at JustSnap.UserActivityHook.Start(Boolean InstallKeyboardHook) in c:\Users\Tagon\Documents\Visual Studio 2013\Projects\JustSnap\JustSnap\UserActivityHook.cs:line 67
   at JustSnap.UserActivityHook.Start() in c:\Users\Tagon\Documents\Visual Studio 2013\Projects\JustSnap\JustSnap\UserActivityHook.cs:line 42
   at JustSnap.UserActivityHook..ctor() in c:\Users\Tagon\Documents\Visual Studio 2013\Projects\JustSnap\JustSnap\UserActivityHook.cs:line 38
   at JustSnap.MainWindow..ctor() in c:\Users\Tagon\Documents\Visual Studio 2013\Projects\JustSnap\JustSnap\MainWindow.xaml.cs:line 29}

How can I find my problem and resolve it ? What you need to know to help me?

Regards, Tagon

EDIT

public void Start(bool InstallKeyboardHook)
        {
            if (hKeyboardHook == 0 && InstallKeyboardHook)
            {
                KeyboardHookProcedure = new HookProc(KeyboardHookProc);
                hKeyboardHook = SetWindowsHookEx(
                    WH_KEYBOARD_LL,
                    KeyboardHookProcedure,
                    Marshal.GetHINSTANCE(
                    Assembly.GetExecutingAssembly().GetModules()[0]),
                    0);
                if (hKeyboardHook == 0)
                {
                    int errorCode = Marshal.GetLastWin32Error();
                    Stop(true, false);
                    throw new Win32Exception(errorCode);
                }
            }
        }

public void Stop(bool UninstallKeyboardHook, bool ThrowExceptions)
        {
            if (hKeyboardHook != 0 && UninstallKeyboardHook)
            {
                int retKeyboard = UnhookWindowsHookEx(hKeyboardHook);
                hKeyboardHook = 0;
                if (retKeyboard == 0 && ThrowExceptions)
                {
                    int errorCode = Marshal.GetLastWin32Error();
                    throw new Win32Exception(errorCode);
                }
            }
        }

Solution

  • Changing:

    Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0])
    

    to:

    System.Diagnostics.Process.GetCurrentProcess().MainModule.BaseAddress
    

    Thats helped me :))