Raheel Khan Raheel Khan - 2 years ago 66
C# Question

Referenced assemblies returns None as ProcessorArchitecture

I have a web project who's DLL I load using

. I then call

The returned
s all have the
set to

The primary DLL's ProcessorArchitecture is x64 while references vary between AnyCPU and x64.

Any idea why I'm not able to pick up the ProcessorArchitecture for these references assemblies?

UPDATE: I just saw this link stating:

Beginning with the .NET Framework 4, this property always returns ProcessorArchitecture.None for reference assemblies.

Is there another way to get to this information?

Answer Source

I had this problem; the code which I ended up using was something like the following:

static void Main() {
    // Load assembly. This can either be by name, or by calling GetReferencedAssemblies().
    Assembly referencedAssembly = Assembly.Load("AssemblyName");

    // Get the PEKind for the assembly, and handle appropriately
    PortableExecutableKinds referenceKind = GetPEKinds(referencedAssembly);
    if((referenceKind & PortableExecutableKinds.Required32Bit) > 0) {
        // is 32 bit assembly
    else if((referenceKind & PortableExecutableKinds.PE32Plus) > 0) {
        // is 64 bit assembly
    else if((referenceKind & PortableExecutableKinds.ILOnly) > 0) {
        // is AnyCpu

static PortableExecutableKinds GetPEKinds(Assembly assembly) {
    PortableExecutableKinds peKinds;
    ImageFileMachine imageFileMachine;
    assembly.GetModules()[0].GetPEKind(out peKinds, out imageFileMachine);
    return peKinds;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download