mscoree - clr header
-
Wednesday, February 20, 2008 7:52 PM
In doing some research into .NET a few question came up that I was hoping someone here could help me answer.
1. Does all .NET binary files (exe and dll) contain a clr header section? Does this section always contain the runtime version info? Does that mean all .NET binary files are aware of which clr version they are compatible?
2. Does mscoree.dll primary use the information found in the clr header section (i.e. "2.00 runtime version") to determine which version of the clr to use?
3. As a developer (using vs2005 and vs2002) can I infuence which .NET version MyAssembly.dll uses? Or does vs2002 automatically set runtime version to 1.1 and vs2005 set it to 2.0 ?
4. How would .NET handle an unmanaged application (mfc) that loads two .NET assemblies that are built with different .NET versions? Would it be a case of first come first serv, so if MyAssembly11 is used first, then MyAssembly20 also needs to use the same clr?
Answers
-
Friday, February 22, 2008 5:59 AMModerator
1. Does all .NET binary files (exe and dll) contain a clr header section? Does this section always contain the runtime version info? Does that mean all .NET binary files are aware of which clr version they are compatible?
Yes, and you can use ILDasm or DumpBin to view this information. For more details, you can visit What CLR version am I or me or this?
2. Does mscoree.dll primary use the information found in the clr header section (i.e. "2.00 runtime version") to determine which version of the clr to use?
The runtime uses the application configuration file and the portable executable (PE) file header to determine which version of the runtime an application supports. If no application configuration file is present, the runtime loads the runtime version specified in the application's PE file header, if that version is available (The version of the CLR installed). For more details, please visit Determining Which Version of the Runtime to Load
3. As a developer (using vs2005 and vs2002) can I infuence which .NET version MyAssembly.dll uses? Or does vs2002 automatically set runtime version to 1.1 and vs2005 set it to 2.0 ?Yes, the runtime version is automatically set. And you can use configuration to influence this. For more details, please visit <supportedRuntime>.
4. How would .NET handle an unmanaged application (mfc) that loads two .NET assemblies that are built with different .NET versions? Would it be a case of first come first serv, so if MyAssembly11 is used first, then MyAssembly20 also needs to use the same clr?
I assume the mfc app use the .net assemblies through COM interop (CCW).
Although COM interop does not actually load the runtime (runtime startup code does), a COM application can target a specific version of the runtime. The startup code loads the latest compatible (2.0 in this issue) runtime version installed on the computer. For more details, please visit Runtime Initialization from a COM Application.
Thanks!
All Replies
-
Friday, February 22, 2008 5:59 AMModerator
1. Does all .NET binary files (exe and dll) contain a clr header section? Does this section always contain the runtime version info? Does that mean all .NET binary files are aware of which clr version they are compatible?
Yes, and you can use ILDasm or DumpBin to view this information. For more details, you can visit What CLR version am I or me or this?
2. Does mscoree.dll primary use the information found in the clr header section (i.e. "2.00 runtime version") to determine which version of the clr to use?
The runtime uses the application configuration file and the portable executable (PE) file header to determine which version of the runtime an application supports. If no application configuration file is present, the runtime loads the runtime version specified in the application's PE file header, if that version is available (The version of the CLR installed). For more details, please visit Determining Which Version of the Runtime to Load
3. As a developer (using vs2005 and vs2002) can I infuence which .NET version MyAssembly.dll uses? Or does vs2002 automatically set runtime version to 1.1 and vs2005 set it to 2.0 ?Yes, the runtime version is automatically set. And you can use configuration to influence this. For more details, please visit <supportedRuntime>.
4. How would .NET handle an unmanaged application (mfc) that loads two .NET assemblies that are built with different .NET versions? Would it be a case of first come first serv, so if MyAssembly11 is used first, then MyAssembly20 also needs to use the same clr?
I assume the mfc app use the .net assemblies through COM interop (CCW).
Although COM interop does not actually load the runtime (runtime startup code does), a COM application can target a specific version of the runtime. The startup code loads the latest compatible (2.0 in this issue) runtime version installed on the computer. For more details, please visit Runtime Initialization from a COM Application.
Thanks!
-
Saturday, February 23, 2008 11:00 AM
Thanks for your reply.
1. Does all .NET binary files (exe and dll) contain a clr header section? Does this section always contain the runtime version info? Does that mean all .NET binary files are aware of which clr version they are compatible?
Yes, and you can use ILDasm or DumpBin to view this information. For more details, you can visit What CLR version am I or me or this?
A very good link. Whats the difference between the CLR header min\max version compared with the metadata version? The latter matches one of the clr versions installed but the clr header min\max version does not tell me anything. Does mscoree.dll use both to determine which clr to load?
// Major runtime version: 0x0002
// Minor runtime version: 0x0005
// Metadata version: v2.0.50727
2. Does mscoree.dll primary use the information found in the clr header section (i.e. "2.00 runtime version") to determine which version of the clr to use?
The runtime uses the application configuration file and the portable executable (PE) file header to determine which version of the runtime an application supports. If no application configuration file is present, the runtime loads the runtime version specified in the application's PE file header, if that version is available (The version of the CLR installed). For more details, please visit Determining Which Version of the Runtime to Load
In the link supplied, step two,
"If the runtime version specified is not available, the runtime searches for a runtime version determined by Microsoft to be compatible with the runtime version in the PE header".
What versions of the clr are compatible with each other? (I Assume this a fix list)
3. Does all versions of mscoree.dll use the same algorithm for selecting the clr version?
-
Monday, February 25, 2008 10:33 AMJust an updated.
Found a very usefull tool that came with VS2005 - corflags.
An example is shown below:
Doing a google I discovered that CLR Header (apparently) means the compiler used on the assembly (All 2.0 framework code will have 2.5 header version, while all 1.0/1.1 compiled code will have 2.0 header version).Code SnippetC:\Prod3.4\Run\bin>corflags a12bb.dll
Microsoft (R) .NET Framework CorFlags Conversion Tool. Version 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.
Version : v1.0.3705
CLR Header: 2.0
PE : PE32
CorFlags : 2
ILONLY : 0
32BIT : 1
Signed : 0
What does Version mean then? In my opinion it seems like Version and CLR Header contains very similar information. There must be a reason for including both versions? Which version does mscoree.dll use?
Thanks for any help. -
Tuesday, February 26, 2008 6:56 AM
If you look at the definition of IMAGE_COR20_HEADER in "CorHdr.h" (shipped by the SDK), or use "dumpbin /clrheader", you can see that "Version" is not a member of the CLR Header structure. The "Version" output by CorFlags should be derrived from some other source (maybe metadata).
In addition, 0x0002 and 0x0005 are the major and minor version, instead of "min\max version".
Generally speaking, .Net versions have backward compatibility. So if v1.x CLR requested is not available, v2.0 will be used.
-
Tuesday, February 26, 2008 7:02 AMModerator--3. Does all versions of mscoree.dll use the same algorithm for selecting the clr version?
Yes, the implementation of this logic will remain very stable among different versions of CLR. -
Tuesday, February 26, 2008 7:50 AM
Ting Wang - MSFT wrote: If you look at the definition of IMAGE_COR20_HEADER in "CorHdr.h" (shipped by the SDK), or use "dumpbin /clrheader", you can see that "Version" is not a member of the CLR Header structure. The "Version" output by CorFlags should be derrived from some other source (maybe metadata).
So in other words the information is not used to determine which clr to load? How can I find out what "Version" refers to and what it is used for? Just to explain why I'm asking. The other day I made as small app that iterate through our companies binary files and execute corflags on each file. From the roughly 60 dotnet files, 2 files used version v1.1.4322 while the rest used v1.0.3705 (all used clr header version 2.0). What can I read into this? What makes these two files different from the others?
Ting Wang - MSFT wrote: Generally speaking, .Net versions have backward compatibility. So if v1.x CLR requested is not available, v2.0 will be used.
Given the above statement, will step 3 in 'Determining Which Version of the Runtime to Load' [1] only be valid if no clr exist?
[1] - http://msdn2.microsoft.com/en-us/library/w671swch.aspx

