调试反射类型加载异常
Debugging Reflection TypeLoadExceptions
如何调试此类错误?
问题文件是System.Memory,版本=4.0.1.1。据我所知,我在我的任何项目中都没有引用这个文件,我已经检查了我导入的 nuget 包的依赖关系,其中 none 个引用了这个文件。
为什么要加载此文件?令人沮丧的是,在带有 ReflectionTypeLoadException 的 InvalidOperationException 中抛出的错误只是一条消息。我无法访问抛出的错误,因为它是在我无权访问的 DLL 中抛出的。该 DLL 构成了我公司框架的一部分。
我有一个非常相似的项目,它使用相同的公司框架 DLL,但没有这个问题。
错误:
Exception thrown: 'System.InvalidOperationException' in ****.dll
ReflectionTypeLoadException errors: [Could not load file or assembly 'System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)][Could not load file or assembly 'System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)][Could not load file or assembly 'System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)][Could not load file or assembly 'System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)][Could not load file or assembly 'System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
Fuslogvw报错如下:
*** Assembly Binder Log Entry (19/01/2021 @ 20:33:19) ***
The operation failed.
Bind result: hr = 0x80131040. No description available.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable C:\SfDevCluster\Data\_App\_Node_0\*******.FabricAppType_App0\********.FabricSvcPkg.Code.1.0.1\**********.FabricSvc.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: DisplayName = System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
(Fully-specified)
LOG: Appbase = file:///C:/SfDevCluster/Data/_App/_Node_0/******.FabricAppType_App0/******.FabricSvcPkg.Code.1.0.1/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = Prescriptions.Api.FabricSvc.exe
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\SfDevCluster\Data\_App\_Node_0\*******.FabricAppType_App0\******.FabricSvcPkg.Code.1.0.1\******.FabricSvc.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/SfDevCluster/Data/_App/_Node_0/******.FabricAppType_App0/*******.FabricSvcPkg.Code.1.0.1/System.Memory.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\SfDevCluster\Data\_App\_Node_0\*******.FabricAppType_App0\*******.FabricSvcPkg.Code.1.0.1\System.Memory.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: System.Memory, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
WRN: Comparing the assembly name resulted in the mismatch: Revision Number
ERR: The assembly reference did not match the assembly definition found.
ERR: Run-from-source setup phase failed with hr = 0x80131040.
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
遵循 Alexei Levenkov 的指示:
我能从 NuGet 获得的 System.Memory 的最早版本是 4.4.0,而不是 Framework。因此,我在解决方案资源管理器中检查了 2 个有问题的项目中的引用,并注意到 System.Memory 4.0.1.0。我很生气忽略了这一点,但是,删除该引用并添加 4.0.1.1 有效并且错误不再发生。
现在我需要弄清楚项目中的哪些引用(不是 NuGet)使用 4.0.1.1 并将其删除。
我错过的重要线索在 Fuslogvw 日志的更下方:
日志:程序集名称是:System.Memory,版本=4.0.1.0,文化=中性,PublicKeyToken=cc7b13ffcd2ddd51。
如果对此给予更多关注,就会发现安装了早期版本,NuGet 中没有该版本,并且会导致我得出上述结论。
如何调试此类错误?
问题文件是System.Memory,版本=4.0.1.1。据我所知,我在我的任何项目中都没有引用这个文件,我已经检查了我导入的 nuget 包的依赖关系,其中 none 个引用了这个文件。
为什么要加载此文件?令人沮丧的是,在带有 ReflectionTypeLoadException 的 InvalidOperationException 中抛出的错误只是一条消息。我无法访问抛出的错误,因为它是在我无权访问的 DLL 中抛出的。该 DLL 构成了我公司框架的一部分。
我有一个非常相似的项目,它使用相同的公司框架 DLL,但没有这个问题。
错误:
Exception thrown: 'System.InvalidOperationException' in ****.dll ReflectionTypeLoadException errors: [Could not load file or assembly 'System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)][Could not load file or assembly 'System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)][Could not load file or assembly 'System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)][Could not load file or assembly 'System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)][Could not load file or assembly 'System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
Fuslogvw报错如下:
*** Assembly Binder Log Entry (19/01/2021 @ 20:33:19) ***
The operation failed.
Bind result: hr = 0x80131040. No description available.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable C:\SfDevCluster\Data\_App\_Node_0\*******.FabricAppType_App0\********.FabricSvcPkg.Code.1.0.1\**********.FabricSvc.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: DisplayName = System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
(Fully-specified)
LOG: Appbase = file:///C:/SfDevCluster/Data/_App/_Node_0/******.FabricAppType_App0/******.FabricSvcPkg.Code.1.0.1/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = Prescriptions.Api.FabricSvc.exe
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\SfDevCluster\Data\_App\_Node_0\*******.FabricAppType_App0\******.FabricSvcPkg.Code.1.0.1\******.FabricSvc.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/SfDevCluster/Data/_App/_Node_0/******.FabricAppType_App0/*******.FabricSvcPkg.Code.1.0.1/System.Memory.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\SfDevCluster\Data\_App\_Node_0\*******.FabricAppType_App0\*******.FabricSvcPkg.Code.1.0.1\System.Memory.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: System.Memory, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
WRN: Comparing the assembly name resulted in the mismatch: Revision Number
ERR: The assembly reference did not match the assembly definition found.
ERR: Run-from-source setup phase failed with hr = 0x80131040.
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
遵循 Alexei Levenkov 的指示:
我能从 NuGet 获得的 System.Memory 的最早版本是 4.4.0,而不是 Framework。因此,我在解决方案资源管理器中检查了 2 个有问题的项目中的引用,并注意到 System.Memory 4.0.1.0。我很生气忽略了这一点,但是,删除该引用并添加 4.0.1.1 有效并且错误不再发生。
现在我需要弄清楚项目中的哪些引用(不是 NuGet)使用 4.0.1.1 并将其删除。
我错过的重要线索在 Fuslogvw 日志的更下方:
日志:程序集名称是:System.Memory,版本=4.0.1.0,文化=中性,PublicKeyToken=cc7b13ffcd2ddd51。
如果对此给予更多关注,就会发现安装了早期版本,NuGet 中没有该版本,并且会导致我得出上述结论。