WPF Xaml Parse Exception未处理

时间:2014-04-22 18:41:43

标签: wpf xaml parsing exception unhandled

  

PresentationFramework.dll中出现未处理的“System.Windows.Markup.XamlParseException”类型异常

     

附加信息:'对类型'JustSnap.MainWindow'的构造函数的调用与指定的绑定约束相匹配引发异常。行号“3”和行位置“9”。

如果我点击查看详细信息:

{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}

如何找到问题并解决问题? 你需要知道什么来帮助我?

此致 Tagon

修改

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);
                }
            }
        }

1 个答案:

答案 0 :(得分:0)

更改:

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

为:

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

多数民众赞成帮助我:))