Open sandboxFocusImprove this doc

PS0096: Invalid Binding Redirection in the Host Configuration

Severity Fatal
Reported by PostSharp
Message Cannot read the binding redirection of the assembly "<Assembly>" in the host configuration file: <Reason>

Cause

PostSharp executes the assemblies of your project at build time, so it must follow the same assembly binding redirections as your application, as Resolution of Assembly Binding Redirections describes. For a project that targets .NET Framework, the build merges the dependentAssembly elements of the binding redirections generated from your project (the postsharp.app.config file in the PostSharp subfolder of the intermediate output folder, for example obj\Debug\net48\PostSharp) and of the files of the PostSharpHostConfigurationFile property into the configuration file of the PostSharp process. PostSharp then reads each dependentAssembly element of this file.

PostSharp reports PS0096, and stops, when it cannot read one of these elements. <Assembly> is the name attribute of the assemblyIdentity element, and <Reason> is the error, for example:

  • The oldVersion or newVersion attribute of the bindingRedirect element is not a version number such as 1.0.0.0, for example 2.* or a version with more than four parts.
  • The oldVersion attribute contains more than one -: it must be a version or a range of two versions, such as 0.0.0.0-4.2.0.0. In this case, <Reason> is the text of an internal assertion.
  • The processorArchitecture attribute of the assemblyIdentity element is not a processor architecture, such as msil, x86 or amd64.

Projects that target .NET Core, .NET 5 and later, or .NET Standard do not use this configuration. This message depends on the configuration files of a .NET Framework project, so no example can show it.

Resolution

  1. Find the dependentAssembly element of <Assembly> in the app.config or web.config file of the project, or in the file that the PostSharpHostConfigurationFile property names. The postsharp.app.config and postsharp.merged.app.config files of the PostSharp subfolder of the intermediate output folder show the configuration that PostSharp actually reads.

  2. Correct the oldVersion, newVersion or processorArchitecture attribute, for example:

    <dependentAssembly>
      <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
    </dependentAssembly>
    
  3. Rebuild the project. When the element is generated by NuGet or by the automatic binding redirections of MSBuild, delete the obj folder first, so that the generated files are created again.

See Also

Other Resources

Resolution of Assembly Binding Redirections
Well-Known MSBuild Properties