无法加载文件或程序集'PresentationUI.Aero2'或其某个依赖项。为什么?

11

在我的WPF应用程序中,启动时出现以下异常:

A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll

Additional information: Could not load file or assembly 
'PresentationUI.Aero2, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' 
or one of its dependencies. 

编辑:使用融合日志,我得到比调用堆栈更有价值的一些信息:

LOG: DisplayName = PresentationUI.Aero2, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
 (Fully-specified)
LOG: Appbase = file:///[...]/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = EngideskLauncher.vshost.exe
Calling assembly : PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: [...]\bin\Debug\EngideskLauncher.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: PresentationUI.Aero2, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///[...]/bin/Debug/PresentationUI.Aero2.DLL.
LOG: Attempting download of new URL file:///file:///[...]/bin/Debug/PresentationUI.Aero2/PresentationUI.Aero2.DLL.
LOG: Attempting download of new URL file:///file:///[...]/bin/Debug/PresentationUI.Aero2.EXE.
LOG: Attempting download of new URL file:///file:///[...]/bin/Debug/PresentationUI.Aero2/PresentationUI.Aero2.EXE.
LOG: All probing URLs attempted and failed.

我觉得奇怪的是,调用程序集是PresentationFramework,显然是一个.NET框架程序集。.NET Framework程序集不会调用不是.NET框架程序集的程序集。无论如何,我在任何地方都找不到PresentationUI.Aero2.DLL,甚至Google似乎也不知道它?

有什么想法吗?

其他信息:

  • .NET Framework 4.0
  • Windows 8.1

嗨CodeCaster,感谢你的提示。如果您能对输出给我一些简短的反馈,我会很高兴。您有什么想法吗? - Marc
嗨,汉斯,你提到的文件夹包含PresentationFramework.Aero2.DLL但不包含PresentationUI.Aero2.DLL。你说的“你怎么在那台机器上得到4.0完全是无法猜测的”是什么意思?我记不起来使用过任何类似于大锤的工具;)谢谢你的帮助! - Marc
我的WPF项目(.NET 4.0, Win8.1)在任何包含FlowDocument的视图中都会抛出完全相同的异常,但是只有当我在Visual Studio的调试器中运行时才会出现。如果我从“bin”文件夹启动可执行文件,则不会出现异常。我创建的一个独立项目在其自己的解决方案中作为独立项目运行时可以正常工作,但是如果将其添加到我的现有解决方案中,则会失败,因此我怀疑我的解决方案存在问题。 - pmcoltrane
嗨,pmcoltrane,在我的情况下,错误自行消失了,我无法确定我改变了什么。我在抛出异常的项目中工作并重新构建它。毫无头绪...我想这就是所谓的Heisen-Bug吧。如果我发现任何信息,我会很高兴你能告诉我! - Marc
1
这个答案解决了我的类似问题: https://dev59.com/cOo6XIcBkEYKwwoYNBdQ - sergeantKK
显示剩余2条评论
2个回答

18

如果你感兴趣的话,这是WPF中一个(良性的)bug。这个异常是第一次出现的机会,可以忽略它。

WPF忘记将Aero2.NormalColor.xaml添加到PresentationUI.dll中。如果你使用你喜欢的反编译工具检查PresentationUI.dll,你会发现各种主题,如Aero.NormalColor.baml等,但没有Aero2.NormalColor.xaml。这会导致WPF尝试查看是否存在外部程序集:

它试图从PresentationUI.dll加载Aero2.NormalColor.baml,并返回nullhttp://referencesource.microsoft.com/#PresentationFramework/src/Framework/System/Windows/SystemResources.cs,773

然后去尝试一个外部程序集: http://referencesource.microsoft.com/#PresentationFramework/src/Framework/System/Windows/SystemResources.cs,554

这将抛出实际的异常: http://referencesource.microsoft.com/#PresentationFramework/src/Framework/System/Windows/SystemResources.cs,706

当使用FlowDocumentFlowDocumentScrollViewer时,通常会观察到这个异常。


2

我曾经遇到过同样的错误,最后发现这是因为我在IDE中开启了“首次机会异常”,实际上这个异常并不重要,你可以忽略它或者继续执行。


所以,这并没有回答为什么会抛出异常的问题。如果我们可以忽略它,你有任何想法为什么会抛出异常吗? - Zack

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接