Open sandboxFocusImprove this doc

PS0097: Host Configuration File Without Assembly Binding Element

Severity Error
Reported by PostSharp
Message The XPath expression '<XPath>' did not evaluate to a valid element in file '<File>'.

Cause

For a project that targets .NET Framework, PostSharp loads the assembly binding redirections that the project needs at build time from the configuration file of the PostSharp process, as Resolution of Assembly Binding Redirections describes. This file is the .config file of the PostSharp executable, in the PostSharp package, or a copy of it in the intermediate output folder (postsharp.merged.app.config) when the build adds the binding redirections of the project to it.

PostSharp looks for the assemblyBinding element with the XPath expression /configuration/runtime/node()[local-name(.)='assemblyBinding'], which is <XPath>. It reports PS0097 when the file <File> exists but has no such element. When the file is not well-formed XML, PostSharp reports PS0095 instead.

The files of the PostSharp package always contain this element, and the build checks it before it adds the redirections of the project, so this message means that the PostSharp package is damaged or was modified. Projects that target .NET Core, .NET 5 and later, or .NET Standard do not read this file. This message depends on the installation of PostSharp, so no example can show it.

Resolution

  1. Open the file <File> and check that it contains a configuration/runtime/assemblyBinding element in the urn:schemas-microsoft-com:asm.v1 namespace.
  2. When <File> is in the PostSharp package, restore the package again: delete the folder of this version of PostSharp from the NuGet package cache (for example %UserProfile%\.nuget\packages\postsharp\<Version>), then run dotnet restore or msbuild -restore.
  3. When <File> is in the intermediate output folder of the project, delete the obj folder of the project and rebuild it.

See Also

Other Resources

Resolution of Assembly Binding Redirections