pm_2 pm_2 - 18 days ago 7
C# Question

Runtime error: Could not load file or assembly - Modules with different CPU types were found

I'm getting the following runtime error in my WCF service.

Could not load file or assembly 'MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.


After some looking around, I found a suggestion to use Assembly Binding Log Viewer, or Process Monitor. Neither or which yielded any information (that is, the log viewer showed nothing at all, and the process viewer didn't see the assembly load being attempted.

I finally came across a suggestion to use this utility (dependency walker) to find out what the assembly was actually looking for. On opening, I got an error immediately; and the log stated the following:

Error: Modules with different CPU types were found.
Warning: At least one delay-load dependency module was not found.
Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.

Error: Modules with different CPU types were found.
Warning: At least one delay-load dependency module was not found.
Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.


According to the module list, it couldn't find these:

API-MS-WIN-CORE-COM-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-ERROR-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-ROBUFFER-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-STRING-L1-1-0.DLL
API-MS-WIN-SHCORE-SCALING-L1-1-0.DLL
DCOMP.DLL
IESHIMS.DLL


Some of these look like they relate to the RT framework; however, this application was developed in .NET 3.5 (actually, that's not strictly true - it was developed in 4.5 and downgraded to 3.5).

Looking at some of these files seems to imply they are quite core Windows files, and oddly, I have used this dll elsewhere in the solution (admittedly on the client) without issue.

I'm using VS2013 although I've tried VS2012 and get the same issue.

I did come across this question which at first glance seems to be the same, although it relates to C++.

Can anyone give me some guidance as to what the issue might be, or what to try next?

Here is my fusion log:

=== Pre-bind state information ===
LOG: DisplayName = MyAssembly.MyLib.XmlSerializers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, processorArchitecture=MSIL (Fully-specified)
LOG: Appbase = file:///c:/myprog/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = myprog.exe
Calling assembly : System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: c:\myprog\bin\Debug\myprog.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: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).


I managed to reduce the library in question down until it was just a single static function that returns a string, and still get the error.

Answer

The thing that always helped me with resolving this error was to take closer look at the part of the error message which says "or one of its dependencies".