You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:.NET 8应用因PresentationFramework程序集无法加载报错(无法复现)

.NET 8应用PresentationFramework加载异常排查问题

应用基础信息

我有一个基于.NET 8.0.401的应用,项目依赖包如下:

>dotnet list xxx.csproj package
Project 'xxx' has the following package references
   [net6.0-windows7.0]:
   Top-level Package                     Requested   Resolved
   > Costura.Fody                        5.7.0       5.7.0
   > MahApps.Metro                       2.4.10      2.4.10
   > Newtonsoft.Json                     13.0.3      13.0.3
   > NLog                                5.3.3       5.3.3
   > System.Net.Http                     4.3.4       4.3.4
   > System.Text.RegularExpressions      4.3.1       4.3.1

通过global.json强制指定.NET版本:

{
  "sdk": {
    "version": "8.0.401"
  }
}

用户运行异常

本地编译运行Debug或Release版本均正常,但有用户运行应用时触发以下未处理异常:

Unhandled exception. System.IO.FileLoadException: Could not load file or assembly 'PresentationFramework, Version=6.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The located assembly's manifest definition does not match the assembly reference. (0x80131040)
File name: 'PresentationFramework, Version=6.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

该用户使用Windows 11 Pro系统,已安装.NET 8,环境看似正常。我并未直接引用PresentationFramework,但GUI依赖的MahApps.Metro可能间接关联此程序集,目前无法复现该问题。

环境差异对比

用户机器情况

用户全局程序集缓存(GAC)中存在多个版本的PresentationFramework,包括6.0.2.0、4.0.0.0等。

开发机器情况

  • GAC中仅存在PresentationFramework 4.0.0.0版本:
>gacutil /u PresentationFramework
Microsoft (R) .NET Global Assembly Cache Utility.  Version 4.0.30319.0
Copyright (c) Microsoft Corporation.  All rights reserved.


Assembly: PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL
Unable to uninstall: assembly is required by one or more applications
Pending references:
              SCHEME: <OPAQUE>  ID: <{71F8EFBF-09AF-418D-91F1-52707CDFA274}>  DESCRIPTION : <.NET Framework Redist Setup>
Number of assemblies uninstalled = 0
Number of failures = 0
  • 已安装的.NET SDK:
>dotnet --list-sdks
8.0.403 [C:\Program Files\dotnet\sdk]
9.0.100-preview.7.24407.12 [C:\Program Files\dotnet\sdk]
  • 执行dotnet list xxx.csproj package --include-transitive,传递依赖中未发现PresentationFramework;添加该NuGet包引用显得不合理。
  • 使用Dependencies (x64)工具检测,显示机器缺失PresentationFramework,但应用仍可正常运行;使用Fusion++工具启动应用无任何记录,无法获取有效加载日志。

核心疑问

  1. 开发机与用户GAC中PresentationFramework的版本差异是否会导致该加载异常?
  2. .NET运行时或GAC与本次程序集加载问题存在怎样的关联?
  3. 若需要追踪运行时DLL加载情况或列出.NET EXE所需依赖,优先使用哪些工具?

内容的提问来源于stack exchange,提问作者BullyWiiPlaza

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 06:55:18