我有一个 Web 项目,我使用 Assembly.ReflectionOnlyLoadFrom(filename)
加载 DLL。 。然后我调用assembly.GetReferencedAssemblies();
.
返回的AssemblyName
都有ProcessorArchitecture
设置为None
.
主要 DLL 的 ProcessorArchitecture 是 x64,而 AnyCPU 和 x64 之间的引用有所不同。
知道为什么我无法获取这些引用程序集的 ProcessorArchitecture 吗?
更新:我刚刚看到这个 link说明:
Beginning with the .NET Framework 4, this property always returns ProcessorArchitecture.None for reference assemblies.
还有其他方法可以获取此信息吗?
最佳答案
我遇到了这个问题;我最终使用的代码如下所示:
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;
}
关于c# - 引用的程序集返回 None 作为 ProcessorArchitecture,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36945117/