| Severity | Error |
| Reported by | PostSharp |
| Message | Exception in .NET strong name API invocation. <Details> |
Cause
When the project has a strong name, PostSharp signs the assembly that it produces with the same key as the C# compiler. On Windows, PostSharp uses the strong name API of the .NET Framework (IClrStrongName, in mscoree.dll) to read the key and to sign the file whenever the PostSharp compiler runs on the .NET Framework, and, on .NET, when the key is in a key container (the KeyContainerName MSBuild property) rather than in a key file.
PostSharp reports PS0240 when this API fails, either while it reads the information of the key or while it signs the file. It is a fatal error: PostSharp stops at once. <Details> names the key file or the key container, or the file being signed, and gives the error of the API. When the error is 0x8013141C, the message adds that access to the C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys folder may be blocked, for example by an antivirus. PostSharp retries several times before it reports this error, and also retries when another process locks the file.
This message depends on the cryptographic configuration of the machine, so no example can show it.
Resolution
- When the project uses a key container, check that the container exists on the machine that runs the build, under the account that runs it, for example with
sn -pc <container> public.snk. A key container is local to a machine: on a build server, install it there, or use a key file instead. - Prefer a key file: set the
AssemblyOriginatorKeyFileMSBuild property to the path of the.snkfile, withSignAssemblyset toTrue, and removeKeyContainerName. With a key file, PostSharp does not call the strong name API on .NET. - When the error is
0x8013141C, check that the account that runs the build can read and writeC:\ProgramData\Microsoft\Crypto\RSA\MachineKeys, and exclude this folder and theobjfolder of the project from the scans of your antivirus. - To see each call that PostSharp makes to the strong name API and the exceptions it gets, build with the
PostSharpTraceMSBuild property set toStrongNameand a build log verbosity of at leastnormal. See Well-Known MSBuild Properties.
See Also
Other Resources