BindingPolicy
Namespace: Dotsider.Core.Analysis.Models
Assembly: Dotsider.Core.dll
Aggregated .NET Framework binding policy assembled from framework unification, machine.config, publisher-policy assemblies, and the application configuration file. Layers are stored in document order with first-match semantics — the same model the CLR applies — and later layers (machine.config > publisher > app > framework unification) override earlier ones when they target the same identity.
public sealed record BindingPolicy : IEquatable<BindingPolicy>Inheritance
Section titled “Inheritance”Object → BindingPolicy
Implements
Section titled “Implements”Constructors
Section titled “Constructors”BindingPolicy(IReadOnlyList<BindingRedirect>, IReadOnlyList<BindingRedirect>, IReadOnlyList<BindingRedirect>, IReadOnlyList<BindingRedirect>, IReadOnlyList<CodeBaseEntry>, IReadOnlyCollection<(string Name, string? PublicKeyToken, string Culture)>, bool, IReadOnlyDictionary<(string Name, string PublicKeyToken), Version>?)
Section titled “BindingPolicy(IReadOnlyList<BindingRedirect>, IReadOnlyList<BindingRedirect>, IReadOnlyList<BindingRedirect>, IReadOnlyList<BindingRedirect>, IReadOnlyList<CodeBaseEntry>, IReadOnlyCollection<(string Name, string? PublicKeyToken, string Culture)>, bool, IReadOnlyDictionary<(string Name, string PublicKeyToken), Version>?)”Aggregated .NET Framework binding policy assembled from framework unification, machine.config, publisher-policy assemblies, and the application configuration file. Layers are stored in document order with first-match semantics — the same model the CLR applies — and later layers (machine.config > publisher > app > framework unification) override earlier ones when they target the same identity.
Parameters:
AppConfigRedirects(IReadOnlyList<BindingRedirect>): Redirects parsed from*.exe.config/*.dll.config.PublisherPolicyRedirects(IReadOnlyList<BindingRedirect>): Redirects parsed frompolicy.<major>.<minor>.<simpleName>assemblies in the GAC.MachineConfigRedirects(IReadOnlyList<BindingRedirect>): Redirects parsed from the architecture-correctmachine.config.FrameworkUnificationRedirects(IReadOnlyList<BindingRedirect>): Redirects produced by the CLR’s built-in unification of well-known framework PKTs.CodeBases(IReadOnlyList<CodeBaseEntry>): CodeBase entries from any policy layer, ordered by precedence (machine > publisher > app).PublisherPolicyDisabledFor(IReadOnlyCollection<String, String, String>>): Identities for which the application configuration set<publisherPolicy apply="no"/>on a specific<dependentAssembly>. Bypasses the publisher-policy layer for those identities.PublisherPolicyDisabledGlobally(Boolean): true when the application configuration set runtime-scoped<publisherPolicy apply="no"/>, suppressing publisher policy for every bind in the app domain — including identities that have no<dependentAssembly>block.FrameworkUnificationTable(IReadOnlyDictionary<String, String>, Version>): Per-identity unification table built by scanningFramework[64]\v4.0.30319at policy load time: maps(Name, PublicKeyToken)for in-box framework assemblies (PKT in FrameworkUnificationPublicKeyTokens) to the version actually shipped in the runtime directory. NetFxArchitecture) consults this map first; references at versions less than or equal to the table version unify to the table version, so a subsequent GAC lookup finds the file at its real GAC location instead of falling through to a post-hoc framework-directory match.
public BindingPolicy(IReadOnlyList<BindingRedirect> AppConfigRedirects, IReadOnlyList<BindingRedirect> PublisherPolicyRedirects, IReadOnlyList<BindingRedirect> MachineConfigRedirects, IReadOnlyList<BindingRedirect> FrameworkUnificationRedirects, IReadOnlyList<CodeBaseEntry> CodeBases, IReadOnlyCollection<(string Name, string? PublicKeyToken, string Culture)> PublisherPolicyDisabledFor, bool PublisherPolicyDisabledGlobally = false, IReadOnlyDictionary<(string Name, string PublicKeyToken), Version>? FrameworkUnificationTable = null)Properties
Section titled “Properties”AppConfigRedirects
Section titled “AppConfigRedirects”Redirects parsed from *.exe.config/*.dll.config.
Returns: IReadOnlyList<BindingRedirect>
public IReadOnlyList<BindingRedirect> AppConfigRedirects { get; init; }CodeBases
Section titled “CodeBases”CodeBase entries from any policy layer, ordered by precedence (machine > publisher > app).
Returns: IReadOnlyList<CodeBaseEntry>
public IReadOnlyList<CodeBaseEntry> CodeBases { get; init; }An empty policy — no redirects, no codeBase, no publisher-policy bypasses.
Returns: BindingPolicy
public static BindingPolicy Empty { get; }FrameworkUnificationRedirects
Section titled “FrameworkUnificationRedirects”Redirects produced by the CLR’s built-in unification of well-known framework PKTs.
Returns: IReadOnlyList<BindingRedirect>
public IReadOnlyList<BindingRedirect> FrameworkUnificationRedirects { get; init; }FrameworkUnificationTable
Section titled “FrameworkUnificationTable”Per-identity unification table built by scanning Framework[64]\v4.0.30319 at policy
load time: maps (Name, PublicKeyToken) for in-box framework assemblies (PKT in
FrameworkUnificationPublicKeyTokens) to the version actually
shipped in the runtime directory. NetFxArchitecture) consults this map first; references
at versions less than or equal to the table version unify to the table version, so a
subsequent GAC lookup finds the file at its real GAC location instead of falling through to
a post-hoc framework-directory match.
Returns: IReadOnlyDictionary<String, String>, Version>
public IReadOnlyDictionary<(string Name, string PublicKeyToken), Version>? FrameworkUnificationTable { get; init; }MachineConfigRedirects
Section titled “MachineConfigRedirects”Redirects parsed from the architecture-correct machine.config.
Returns: IReadOnlyList<BindingRedirect>
public IReadOnlyList<BindingRedirect> MachineConfigRedirects { get; init; }PublisherPolicyDisabledFor
Section titled “PublisherPolicyDisabledFor”Identities for which the application configuration set
<publisherPolicy apply="no"/> on a specific
<dependentAssembly>. Bypasses the publisher-policy layer for those identities.
Returns: IReadOnlyCollection<String, String, String>>
public IReadOnlyCollection<(string Name, string? PublicKeyToken, string Culture)> PublisherPolicyDisabledFor { get; init; }PublisherPolicyDisabledGlobally
Section titled “PublisherPolicyDisabledGlobally”true when the application configuration set runtime-scoped
<publisherPolicy apply="no"/>, suppressing publisher policy for every bind in
the app domain — including identities that have no <dependentAssembly> block.
Returns: Boolean
public bool PublisherPolicyDisabledGlobally { get; init; }PublisherPolicyRedirects
Section titled “PublisherPolicyRedirects”Redirects parsed from policy.<major>.<minor>.<simpleName> assemblies in the GAC.
Returns: IReadOnlyList<BindingRedirect>
public IReadOnlyList<BindingRedirect> PublisherPolicyRedirects { get; init; }Methods
Section titled “Methods”Apply(AssemblyRefInfo, NetFxArchitecture)
Section titled “Apply(AssemblyRefInfo, NetFxArchitecture)”Resolves the effective identity for the requested reference by walking the policy layers in CLR walk order — app config first, then publisher policy (skipped if bypassed for this identity), then machine.config — with later layers overriding earlier ones. Framework unification supplies the baseline mapping when no later layer rewrites the identity. The returned tuple includes which layer produced the rewrite, so callers can attach an AppliedPolicy to the resolution result.
Parameters:
requested(AssemblyRefInfo): The identity exactly as named by the metadata reference.architecture(NetFxArchitecture): Effective process bitness, used to filterprocessorArchitectureentries.
Returns: ValueTuple<AssemblyRefInfo, AppliedPolicy>
The effective identity and the policy layer that produced any rewrite. AppliedPolicy is null when no layer rewrote the identity.
public (AssemblyRefInfo Effective, AppliedPolicy? Applied) Apply(AssemblyRefInfo requested, NetFxArchitecture architecture)FindCodeBaseFor(AssemblyRefInfo)
Section titled “FindCodeBaseFor(AssemblyRefInfo)”Returns the <codeBase> entry that anchors the supplied effective identity, or
null when no codeBase is configured for that identity.
Parameters:
effective(AssemblyRefInfo): The post-policy identity to look up.
Returns: CodeBaseEntry
A matching CodeBaseEntry, or null.
public CodeBaseEntry? FindCodeBaseFor(AssemblyRefInfo effective)LoadFrom(string?, NetFxArchitecture, IReadOnlyList<string>, NetFxRuntimeVersion)
Section titled “LoadFrom(string?, NetFxArchitecture, IReadOnlyList<string>, NetFxRuntimeVersion)”Loads policy from the analyzer’s app/exe config plus machine.config and any publisher-policy
assemblies discovered in the supplied GAC roots. Errors are handled per CLR semantics:
malformed XML at the document level yields an empty policy for that source; individual
invalid <dependentAssembly>/<bindingRedirect> sections are silently
dropped and the rest of the file continues to apply.
Parameters:
appConfigPath(String): Path to the application configuration file, or null.architecture(NetFxArchitecture): Effective process bitness, controls whichmachine.configto read.gacRoots(IReadOnlyList<String>): GAC root directories to scan for publisher-policy assemblies.runtimeVersion(NetFxRuntimeVersion): CLR generation the policy targets. Switches the machine.config path, GAC token format, reference-assemblies tree, andappliesTofilter between Clr2 and Clr4.
Returns: BindingPolicy
A populated BindingPolicy.
public static BindingPolicy LoadFrom(string? appConfigPath, NetFxArchitecture architecture, IReadOnlyList<string> gacRoots, NetFxRuntimeVersion runtimeVersion = NetFxRuntimeVersion.Clr4)ParseConfigFile(string?, PolicyLayer, NetFxRuntimeVersion)
Section titled “ParseConfigFile(string?, PolicyLayer, NetFxRuntimeVersion)”Parses a single configuration file (app config, machine.config, or a publisher-policy assembly’s embedded XML resource) into a BindingPolicyParseResult. Exposed so callers that already have the file path can avoid re-parsing.
Parameters:
path(String): Path to the configuration file, or null.source(PolicyLayer): Policy layer to attribute parsed entries to.runtimeVersion(NetFxRuntimeVersion): CLR generation the parse targets. Filters<assemblyBinding appliesTo="...">blocks: Clr2 acceptsv2/v2.0/v2.0.50727; Clr4 acceptsv4/v4.*; an emptyappliesTomatches both.
Returns: BindingPolicyParseResult
The parsed result; an empty result on missing file or malformed XML.
public static BindingPolicyParseResult ParseConfigFile(string? path, PolicyLayer source, NetFxRuntimeVersion runtimeVersion = NetFxRuntimeVersion.Clr4)