【发布时间】:2016-05-17 11:21:38
【问题描述】:
所以,我有一个带有 GUI 的 C# 应用程序,它是用 XAML 编写的。刚才我的应用程序正在运行并正确显示,但是,在对 XAML 中的一个 GUI 元素进行了一些小的更改(实际上只是调整大小和移动按钮)之后,我再次构建了我的代码,但现在在尝试运行它时,我收到一条错误消息:
FileNotFoundException 未被用户代码处理
错误是突出显示该行:
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 消息上单击“查看详细信息...”时,System.IO.FileNotFoundException 会说:
{"无法加载文件或程序集 'WebKit.Interop, Version=533.0.0.0, Culture=neutral, PublicKeyToken=b967213f6d29a3be' 或其依赖项之一。系统找不到指定的文件。":"WebKit.Interop , 版本=533.0.0.0, 文化=中性, PublicKeyToken=b967213f6d29a3be"}
InnerException 具有价值:
空
FileName 是:
WebKit.Interop,版本=533.0.0.0,文化=中性,PublicKeyToken=b967213f6d29a3be
FusionLog 是:
=== 预绑定状态信息 === 日志:DisplayName = WebKit.Interop,版本 = 533.0.0.0,文化 = 中性,PublicKeyToken = b967213f6d29a3be (完全指定) 日志:Appbase = file:///C:/.../bin/Debug/ 日志:初始 PrivatePath = NULL
调用程序集:WebKitBrowser,Version=0.5.0.0,Culture=neutral,PublicKeyToken=b967213f6d29a3be。
LOG:此绑定在默认加载上下文中开始。 LOG:使用应用程序配置文件:C:...\bin\Debug\WpfApplication1.vshost.exe.Config LOG:使用主机配置文件: LOG:使用 C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config 中的机器配置文件。 日志:后策略参考:WebKit.Interop,版本=533.0.0.0,文化=中性,PublicKeyToken=b967213f6d29a3be 日志:正在尝试下载新的 URL 文件:///C:/.../bin/Debug/WebKit.Interop.DLL。 日志:正在尝试下载新的 URL 文件:///C:/.../bin/Debug/WebKit.Interop/WebKit.Interop.DLL。 日志:正在尝试下载新的 URL 文件:///C:/.../bin/Debug/WebKit.Interop.EXE。 日志:正在尝试下载新的 URL 文件:///C:/.../bin/Debug/WebKit.Interop/WebKit.Interop.EXE。
当我查看FusionLog 指定的文件夹位置时,我可以看到它正在寻找的WpfApplication1.vshost.exe 文件...(有WpfApplication1.vshost 应用程序清单、WpfApplication1.vshost 应用程序、WpfApplication1.vshost.exe XML 配置& WpfApplication1.vshost.exe.manifest MANIFEST 文件都在那个位置......(以及其他一些:.exe、.exe.manifestSource Browser Database 等)
编辑
发生此异常的代码就在我的 MainWindow.xaml.cs 类的构造函数上方,即我声明该类的全局变量的位置:
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();
并说它
无法加载文件或程序集 WebKit.Interop,版本 533.0.0.0 ...
【问题讨论】:
-
为 AppDomain.Current.UnhandledException 添加处理程序并发布完整的堆栈跟踪和 InnerException(如果有)
-
不知道为什么,但无法在 Android App 上编辑评论。看这里msdn.microsoft.com/en-US/library/…
-
使用 Visual Studio 听起来很有趣 - 完全干净,关闭 Visual Studio,然后重新打开。很遗憾,但这类问题往往会在此之后得到解决。
-
是的,我尝试的第一件事是清理/重建...还尝试清理,然后关闭并重新打开,然后再次运行,但我遇到了同样的问题...
-
最可能的原因是文件 (webkit.interop.dll) 不存在 - 你看了吗?或者 dll 是 32 位,而您编译的是 64 位,反之亦然。点击关闭“喜欢 32 位”,为 dll 选择正确的构建
标签: c# wpf xaml user-interface filenotfoundexception