【问题标题】:"Could not load file or assembly 'PresentationUI.Aero2' or one of its dependencies." Why not?“无法加载文件或程序集‘PresentationUI.Aero2’或其依赖项之一。”为什么不?
【发布时间】:2014-11-04 11:16:07
【问题描述】:

在我的 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 Framework 程序集的程序集。无论如何,我在任何地方都找不到 PresentationUI.Aero2.DLL,甚至 Google 似乎都不知道它的任何信息??

有什么想法吗?

附加信息:

  • .NET Framework 4.0
  • Windows 8.1

【问题讨论】:

  • 启用融合日志或使用 ProcMon 找出它试图加载的文件。见How to debug “Could not load file or assembly” runtime errors?
  • 您好 CodeCaster,感谢您的提示。如果您能给我简短的输出反馈,我会很高兴。你有什么想法吗?
  • 嗨,Hans,您提到的文件夹包含PresentationFramework.Aero2.DLL,但不包含PresentationUI.Aero2.DLL。你是什​​么意思“你是如何在那台机器上获得 4.0 的完全无法猜测的”?我不记得用过什么大锤了;)谢谢你的帮助!
  • 我的 WPF 项目(.NET 4.0、Win8.1)对于包含 FlowDocument 的任何视图都抛出完全相同的异常,但在我使用 Visual 中的调试器运行时工作室。如果我从bin 文件夹启动可执行文件,也不例外。我作为独立项目创建的单独项目在其自己的解决方案中作为独立项目运行时可以工作,但如果我将其添加到现有解决方案中则会失败,因此我怀疑我的解决方案有问题。
  • 这个答案解决了我的类似问题:stackoverflow.com/questions/17335712/…

标签: c# wpf dll


【解决方案1】:

如果您有兴趣,这是 WPF 中的一个(良性)错误。例外是第一次发生,可以忽略。

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 中停止,因为我第一次打开了机会异常,异常实际上并不重要,您可以忽略或继续跳过它。

    【讨论】:

    • 因此,这并不能回答为什么抛出异常的问题。如果我们可以忽略它,您知道为什么会抛出它吗?
    猜你喜欢
    • 2021-12-12
    • 2012-01-14
    • 1970-01-01
    相关资源
    最近更新 更多