The rules that specify the acceptable versions of an assembly are called version policies. Version policies are expressed using the <BindingPolicy> tag in configuration files. For more information on assembly versioning in the NGWS runtime, see Version Policy.
Configuration files can be used to override the manifest information. For example, the manifest of an assembly records the version number of each dependency at the time the assembly was compiled. In some cases, it may be acceptable to run with different versions of the dependent assemblies that those present at build time. For example, even if version 5.0.0.0 of a dependent assembly was present at build time, a more recent version, such as version 5.0.1.0 may be acceptable at runtime. Configuration files can also be used to change version policy if a version of a dependency causes an application to stop working. In this case, configuration information can be used to “roll back” to a specific version of a dependency that was present at build time.
The version policies supported in configuration files include:
The default version policy takes the version of the dependent assembly that is recorded in the manifest and matches the major and minor numbers exactly, then takes the latest build and revision numbers. In other words, of the four numbers that make up the version number, the first two must match exactly and the highest of the build and revision numbers are used. For example, if the runtime is given a reference to version 5.0.11.0, and a version 5.0.11.12 is present in the global assembly cache, version 5.0.11.12 will be used.
There are a few points to consider about the default version policy. First, the “use latest” behavior described above only applies to the build and revision portions of the version number. The policy of taking the latest build and revision is often referred to as Automatic QFE Policy. This QFE policy allows software vendors to release critical bug fixes without requiring dependent applications to be rebuilt or reconfigured. It is worth noting that this policy is implicit in that there is nothing that the runtime does to enforce that a QFE is in fact backward compatible with the version it is replacing. The runtime never implicitly takes the latest major and minor numbers because they are, by definition, incompatible with what is being requested.
Second, the runtime only looks in the global assembly cache for QFEs. This is important. If a search path is specified in a configuration file, the runtime does not look at all assemblies on the path, searching for the one with the highest build and revision number. The performance cost of doing this would be prohibitive.
The Bind to a specific version policy allows the developer to specify a particular assembly version using the BindingPolicy tag in a configuration file. This policy allows you to bind to a different version of an assembly than the version recorded in the manifest. The policy can be used to map either references to a specific version of a dependency or references to all versions of a dependency.
For example, the following configuration file entry maps references to all versions of an assembly called calcr to version 6.0.0.0:
<BindingPolicy> <BindingRedir Name="Calcr" Originator="32ab4ba45e0a69a1" Version="*" VersionNew="6.0.0.0" UseLatestBuildRevision="yes"/> </BindingPolicy>
The two previously described polices employ automatic QFE policy, that is they will use the latest build and revision number available. There are times when this is not desirable, such as when a QFE is applied and it works for some applications but breaks others. In this scenario, the administrator or developer could disable the automatic QFE policy that have broken because of the update.
This policy also uses the BindingPolicy tag in a configuration file. The attribute UseLatestBuildRevision is set to no to disable automatic QFE policy for references to a particular assembly. For example, this excerpt from a configuration file binds all references to an assembly called calcr to exactly version 6.1.1212.14; no QFEs to that version will be picked up:
<BindingPolicy> <BindingRedir Name="Calcr" Originator="32ab4ba45e0a69a1" Version="*" VersionNew="6.1.1212.14" UseLatestBuildRevision="no"/> </BindingPolicy>
The Safe Mode policy is used to ensure that the versions of the assemblies built and tested together are the same versions that are run together after the application is deployed. The safety mode policy can also be used to revert to a known state in the presence of failures caused by running with incompatible or buggy versions of dependnet assemblies.
Safe mode always applies to an entire application, not to individual assembly references. The runtime ignores any other version policies and binds to exactly the versions of the dependent assemblies specified in the manifest. All four parts of the version number are checked; no QFEs are applied.
The safe mode policy uses the BindingMode tag in the configuration files. The following example enables the safe mode policy:
<BindingMode> <AppBindingMode Mode="safe"/> </BindingMode>
For more information on configuration files, see Creating Configuration Files.