c# - "Could not load file or assembly ' PresentationUI.Aero2 ' or one of its dependencies."为什么不呢?

标签 c# wpf dll

在我的 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. 

编辑:使用融合日志,我得到了比调用堆栈更有值(value)的信息:

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

最佳答案

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

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

这会尝试从 PresentationUI.dll 加载 Aero2.NormalColor.baml 并返回 null: http://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 时通常会观察到此异常。

关于c# - "Could not load file or assembly ' PresentationUI.Aero2 ' or one of its dependencies."为什么不呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26733790/

相关文章:

c# - 顺时针绘制实心圆

wpf - MVVM。在某些情况下向 View 添加代码是否合理?

c# - System.IO.Ports 5.0 NuGet 包在我的解决方案中不起作用

c++ - 在C#项目中,如何引用用C++编写并用/clr编译的项目?

c# - T4 模板 typeOf(List<>) 导致错误但在 C# 类中有效

c# - 使用 C# 在 sql 数据库中插入日期时间值

c# - 在 WPF 中将形状转换为可重用的几何图形

c - 将整数与从 VBA 调用的 dll 中的硬编码值进行比较的问题

c++ - 将 DLL C++ 类库移植到 Visual Studio 的问题

c# - 在 C# Razor 中将字符串呈现为 HTML