How do I detect the supported framework architecture (x86 or x86-64) in Mono and .NET?
In .NET/Windows there is the PROCESSOR_ARCHITECTURE
environment variable which identifies whether a running process is x32, x64 or IA64.
There's also the GetNativeSystemInfo
API method which can tell whether Windows OS supports 开发者_开发问答x86-64.
Is it true that there always will be an x64 version of .NET Framework as long as x86 version available on Windows x64? Or are there any means to detect what platforms are supported by the .NET installation on the machine?
What about Mono/Linux or other non-Microsoft implementations? Can the x86 version of Mono run on x86-64 Linux? How do I detect (programmatically) what platforms are supported by a Mono installation?
Added 16.11.2010
I’m developing a kind of plugin system (ok, I know there is AddIns
system but it is too flooded with pipeline assemblies). What I want to do is to find out what kinds of assemblies can be loaded in the running process (represented by a platform neutral assembly) and what assembly architectures can be executed by the system in the isolated process.
Is it true that there always will be an x64 version of .NET Framework as long as x86 version available on Windows x64?
Consider if this were not true. That would mean that it was possible, on a x64 edition of Windows, to install only x86 or only x64 .NET. But there is no such installer from MS, so it would only be possible with a third party customised installer.
As well as presumably violating the MS EULA, I would be very reluctant to trust such an installation (what else has it missed out? Has it got the part of .NET It is supposed to install right?)
As the MS install is free to use there seems no incentive for someone to put in the work to create such a custom install I conclude: on x64 Windows if .NET is installed for one bitness then it is installed for both.
(Note, if I recall correctly this doesn't apply before .NET 2, for 1.1 and 1.0 there was no x64 .NET.)
Check Environment.Is64BitProcess
.
On the other hand, why do you need to detect this? The only valid scenario I can think of is P/Invoke, which already loads the correct (x86/x64/other) version of the binary libraries. Also, there are more possible architectures than x86 and x64: even when limiting your code to Microsoft .Net implementation, you can be running on Itanium as well.
For other platforms, see here:
http://mjhutchinson.com/journal/2010/01/25/integrating_gtk_application_mac
It has some code to more reliably detect OS X, which identifies itself as UNIX.
精彩评论