C# FileNotFoundException 未被用户代码处理

C# FileNotFoundException was unhandled by user code

所以,我有一个带有 GUI 的 C# 应用程序是用 XAML 编写的。我的应用程序刚刚 运行 正在正常显示,但是,在对 XAML 中的一个 GUI 元素进行了一些小的更改(实际上只是调整大小和移动按钮)之后,我构建了我的代码再次,但现在当尝试 运行 它时,我收到错误消息:

FileNotFoundException was unhandled by user code

错误是突出显示行:

WebKit.WebKitBrowser browser = new WebKit.Browser();

在我的 MainWindow.xaml.cs 文件中(MainWindow.xaml 是我重新定位其中一个 GUI 元素的 GUI 源文件)。

我以前遇到过这个错误,并通过转到项目 --> 添加引用并选中 'WindowsFormsIntegration' 的复选框来修复它...但是,我已经仔细检查了这个,它仍处于选中状态。

我查看了我的文件夹结构,可以看到 WebKit.Interop.dll 文件存在于我的 Debug 和 Release 文件夹中...

我也试过撤消我对 GUI 所做的更改,重新构建并再次 运行 代码,但我得到了同样的错误。

有人知道这是为什么吗?我是否不小心点击/按下了我不应该点击的东西?我该如何解决这个问题?

编辑

当我在显示的 FileNotFoundException was unhandled by user code 消息上单击 'View Detail...' 时,System.IO.FileNotFoundException 显示:

{"Could not load file or assembly 'WebKit.Interop, Version=533.0.0.0, Culture=neutral, PublicKeyToken=b967213f6d29a3be' or one of its dependencies. The system cannot find the file specified.":"WebKit.Interop, Version=533.0.0.0, Culture=neutral, PublicKeyToken=b967213f6d29a3be"}

InnerException 的值为:

null

FileName是:

WebKit.Interop, Version=533.0.0.0, Culture=neutral, PublicKeyToken=b967213f6d29a3be

FusionLog是:

=== Pre-bind state information === LOG: DisplayName = WebKit.Interop, Version=533.0.0.0, Culture=neutral, PublicKeyToken=b967213f6d29a3be (Fully-specified) LOG: Appbase = file:///C:/.../bin/Debug/ LOG: Initial PrivatePath = NULL

Calling assembly : WebKitBrowser, Version=0.5.0.0, Culture=neutral, PublicKeyToken=b967213f6d29a3be.

LOG: This bind starts in default load context. LOG: Using application configuration file: C:...\bin\Debug\WpfApplication1.vshost.exe.Config LOG: Using host configuration file: LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config. LOG: Post-policy reference: WebKit.Interop, Version=533.0.0.0, Culture=neutral, PublicKeyToken=b967213f6d29a3be LOG: Attempting download of new URL file:///C:/.../bin/Debug/WebKit.Interop.DLL. LOG: Attempting download of new URL file:///C:/.../bin/Debug/WebKit.Interop/WebKit.Interop.DLL. LOG: Attempting download of new URL file:///C:/.../bin/Debug/WebKit.Interop.EXE. LOG: Attempting download of new URL file:///C:/.../bin/Debug/WebKit.Interop/WebKit.Interop.EXE.

当我查看 FusionLog 指定的文件夹位置时,我可以看到它正在寻找的 WpfApplication1.vshost.exe 文件...(有 WpfApplication1.vshost 应用程序清单,WpfApplication1.vshost Application, WpfApplication1.vshost.exe XML Configuration & WpfApplication1.vshost.exe.manifest MANIFEST files all in the location...(以及其他一些:.exe, .exe.manifest Source Browser Database, 等)

编辑

发生此异常的代码就在我的 MainWindow.xaml.cs class 的构造函数上方,即我为 class 声明全局变量的地方:

using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Threading;
using System.Threading.Tasks;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Xml;
using System.Windows.Media;
using System.Windows.Forms;
using WebKit;
using System.Collections;

namespace Agent
{
    public partial class MainWindow : Window
    {
        ...
        System.Windows.Forms.Integration.WindowsFormsHost host = new System.Windows.Forms.Integration.WindowsFormsHost();
        WebKit.WebKitBrowser browser = new WebKit.WebKitBrowser();

        ...
    }
}

线路抛出异常:

WebKit.WebKitBrowser browser = new WebKit.WebKitBrowser();

并说

Could not load the file or assembly WebKit.Interop, Version 533.0.0.0 ...

这里的问题是我做了 'rebuild',而不是再次构建我的代码,并且编译器从我的构建文件夹中删除了 webkit.interop.dll 文件。再次手动将 webkit.interop.dll 从发布版本文件夹复制到调试版本文件夹后,问题就解决了。