Skip to content

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>

ObjectBindingPolicy

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 from policy.&lt;major&gt;.&lt;minor&gt;.&lt;simpleName&gt; assemblies in the GAC.
  • MachineConfigRedirects (IReadOnlyList<BindingRedirect>): Redirects parsed from the architecture-correct machine.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 &lt;publisherPolicy apply="no"/&gt; on a specific &lt;dependentAssembly&gt;. Bypasses the publisher-policy layer for those identities.
  • PublisherPolicyDisabledGlobally (Boolean): true when the application configuration set runtime-scoped &lt;publisherPolicy apply="no"/&gt;, suppressing publisher policy for every bind in the app domain — including identities that have no &lt;dependentAssembly&gt; block.
  • FrameworkUnificationTable (IReadOnlyDictionary<String, String>, Version>): 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.
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)

Redirects parsed from *.exe.config/*.dll.config.

Returns: IReadOnlyList<BindingRedirect>

public IReadOnlyList<BindingRedirect> AppConfigRedirects { get; init; }

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; }

Redirects produced by the CLR’s built-in unification of well-known framework PKTs.

Returns: IReadOnlyList<BindingRedirect>

public IReadOnlyList<BindingRedirect> FrameworkUnificationRedirects { get; init; }

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; }

Redirects parsed from the architecture-correct machine.config.

Returns: IReadOnlyList<BindingRedirect>

public IReadOnlyList<BindingRedirect> MachineConfigRedirects { get; init; }

Identities for which the application configuration set &lt;publisherPolicy apply="no"/&gt; on a specific &lt;dependentAssembly&gt;. Bypasses the publisher-policy layer for those identities.

Returns: IReadOnlyCollection<String, String, String>>

public IReadOnlyCollection<(string Name, string? PublicKeyToken, string Culture)> PublisherPolicyDisabledFor { get; init; }

true when the application configuration set runtime-scoped &lt;publisherPolicy apply="no"/&gt;, suppressing publisher policy for every bind in the app domain — including identities that have no &lt;dependentAssembly&gt; block.

Returns: Boolean

public bool PublisherPolicyDisabledGlobally { get; init; }

Redirects parsed from policy.&lt;major&gt;.&lt;minor&gt;.&lt;simpleName&gt; assemblies in the GAC.

Returns: IReadOnlyList<BindingRedirect>

public IReadOnlyList<BindingRedirect> PublisherPolicyRedirects { get; init; }

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 filter processorArchitecture entries.

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)

Returns the &lt;codeBase&gt; entry that anchors the supplied effective identity, or null when no codeBase is configured for that identity.

Parameters:

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 &lt;dependentAssembly&gt;/&lt;bindingRedirect&gt; 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 which machine.config to 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, and appliesTo filter 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 &lt;assemblyBinding appliesTo="..."&gt; blocks: Clr2 accepts v2/v2.0/v2.0.50727; Clr4 accepts v4/v4.*; an empty appliesTo matches 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)