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

后端 未结 2 603
你的背包
你的背包 2020-12-19 05:22

I need to determine programmatically whether an assembly is x86, x64 or AnyCPU? There is an almost identical question, but the solution that it provides

Ass         


        
相关标签:
2条回答
  • 2020-12-19 05:56

    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.

    0 讨论(0)
  • 2020-12-19 05:57

    Solution how to determinate this just by code without reflection nor thirdparty SW can be found here: How to determine if a .NET assembly was built with platform target AnyCPU, AnyCPU Prefer32-bit, x86, x64 without using reflection and third party SW

    0 讨论(0)
提交回复
热议问题