Sxs’ runtime behavior is built on top of the concept of Activation Context. (For more details on Activation Context, please visit MSDN. I have published an article on it early.)
You can use API CreateActCtx to create an activation context. CreateActCtx requires a source manifest. Optionally, you can also specify an assembly directory (which is commonly referred as application base.), language, processorArchitecture, and resource name if the source is a PE image. For the optional parameters, if they are not specified, they are automatically resolved from the source manifest and the OS environment.
The source manifest can include dependencies on other Sxs assemblies. For example, most people use a Sxs manifest that depends on comctl32 v6 to enable Windows XP Look & Feel.
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <assemblyIdentity version="18.104.22.168" name="Microsoft.FUSLOGVW" type="win32" /> <description>Microsoft .Net Framework Assembly Binding Log Viewer</description> <dependency> <dependentAssembly> <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="22.214.171.124" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*" /> </dependentAssembly> </dependency> </assembly>
When the source manifest includes dependencies, Sxs needs to resolve the dependencies. The process of mapping the dependencies to a physical Sxs manifest file is called binding.
Binding can be divided into two phases: Policy and Probing.
There are two kinds of binding policies in Sxs: Application Policy and Publisher Policy. Just like CLR, application policy is applied to the whole application, while publisher policy is applied to a single assembly for all the applications.
The behaviors have some subtle differences in different OSes:
The Windows Server 2003 behavior is the same as CLR.
Windows ships a publisher policy for every QFE to windows Sxs assemblies. I haven’t yet seen anyone use application policy inside Microsoft.
After binding policies are applied, Sxs will start probing for the manifest file.
The probing sequence is documented in MSDN Assembly Searching Sequence. There are also some subtle behavior differences in different OSes:
For portability you should always embed the manifest into the dll if possible.
You are allowed to wildcarding certain attributes in dependencies. In our example above, processorArchitecture and language are wildcarded.
When the attribute is wildcarded, Sxs will use some heuristics to figure out which value to use for probing.
For processorArchitecture, the heuristics is following:
1. If processorArchitecture is explicitly specified and the processorArchitecture is Wow64, the fallback is x86. Otherwise, nofallback.2. If the processorArchitecture is wildcarded, the fallback list is of the following sequence:a. 32 bit OS:
In Windows XP and Server 2003: x86->None
In Windows Vista: x86->MSIL->Noneb. 64 bit OS:
In Windows XP and Server 2003: IA64/AMD64->None
In Windows Vista: IA64/AMD64->MSIL->None
For language, Sxs queries the system language settings, and probe the manifest from more specific culture to no culture. For example: en-us -> en -> None.
Only processorArchitecture and language are allowed to be wildcarded.
Sxs is case sensitive when comparing attributes. Be sure that the casing of the attribute is the same in the dependencies and in the manifest file.