Debugging Reflection TypeLoadExceptions

0

How do I debug this type of error?

The problem file is System.Memory, Version=4.0.1.1. From what I can see, I have no references to this file in any of my projects and I've checked the dependencies of my imported nuget packages and none of them reference this file.

Why is this file being loaded? Frustratingly, the error that is thrown within an InvalidOperationException with the ReflectionTypeLoadException simply being a message. I don't have access to error being thrown as it is thrown in a DLL I don't have access to. That DLL forms part of my companies framework.

I have a very similar project that uses the same company framework DLLs which doesn't have this problem.

The Error:

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)]

The error from Fuslogvw is as follows:

*** 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.
c#
dll
azure-service-fabric
asked on Stack Overflow Jan 19, 2021 by Martin Stewart • edited Jan 19, 2021 by Alexei Levenkov

1 Answer

1

Following Alexei Levenkov's instructions:

The earliest version I could get of System.Memory from NuGet was 4.4.0, and not for Framework. So I checked the references in 2 of the offending projects in solution explorer and noticed System.Memory 4.0.1.0. I'm annoyed for overlooking that, however, removing that reference and adding 4.0.1.1 worked and the error no longer occurs.

Now I need to figure out which of the references in the project (not NuGet) use 4.0.1.1 and remove it.

The vital clue I missed was further down in the Fuslogvw log:

LOG: Assembly Name is: System.Memory, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51.

Paying more attention to that would have revealed an earlier version was installed, one that wasn't available in NuGet and would have lead me to the above conclusion.

answered on Stack Overflow Jan 19, 2021 by Martin Stewart

User contributions licensed under CC BY-SA 3.0