2016-04-29 16 views
2

私はAssembly.ReflectionOnlyLoadFrom(filename)を使用してロードするDLLのWebプロジェクトを持っています。私はassembly.GetReferencedAssemblies();に電話します。参照アセンブリはProcessorArchitectureとして返しません

返されたAssemblyNameのすべてがをNoneに設定しています。

プライマリDLLのProcessorArchitectureはx64で、参照はAnyCPUとx64で異なります。

なぜ私はこれらの参照アセンブリのProcessorArchitectureを選ぶことができないのですか?

UPDATE:私はちょうどこのlinkは述べました:

を.NET Frameworkの4以降では、このプロパティは常に参照アセンブリのためのProcessorArchitecture.Noneを返します。

この情報にアクセスする別の方法はありますか?

+1

[Module.GetPEKind()](https://msdn.microsoft.com/en-us/library/system.reflection)を試したことがありますか? module.getpekind(v = vs.110).aspx)? – elchido

答えて

1

この問題がありました。私が使ったコードは次のようなものでした:

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; 
} 
関連する問題