How to check programmatically whether a managed assembly is x86, x64 or AnyCPU?

This question's been covered already:

  • How to Tell if a .NET Assembly Was Compiled as x86, x64 or Any CPU
  • How to determine if a .NET assembly was built for x86 or x64?
  • How can I get the processor architecture of an assembly dll?

But the answers are incomplete, suggesting use of Assembly.LoadFrom. That's a terrible idea, since it will run code from the assembly, in addition to failing if the bitness doesn't match your process.

Instead, you should use Assembly.ReflectionOnlyLoadFrom. This lets you read the metadata without actually loading any code, and therefore there's no need for the architecture to be correct.