| Severity | Warning |
| Reported by | PostSharp |
| Message | The assembly has no public key, so PostSharp does not sign it although the SignAssembly property is true. Sign the assembly in the project, or set the SignAssembly property to false. |
Cause
PostSharp rewrites the assembly that the C# or Visual Basic compiler produced. When this assembly is signed, PostSharp signs the woven assembly again with the same key, without any setting: it reads the key file of the project and the strong-name attributes of the assembly.
The SignAssembly property of the PostSharp compiler forces signing. PostSharp.targets sets it from the PostSharpSignAssembly MSBuild property, and you can also set it in the PostSharpProperties MSBuild property. PostSharp can only sign an assembly that has a public key in its manifest. When SignAssembly is true but the assembly that the compiler produced has no public key, because the project itself is not signed, PostSharp reports PS0074 and writes the woven assembly without a strong name.
In the following example, the @Property directive of the test sets SignAssembly to true, as <PostSharpSignAssembly>True</PostSharpSignAssembly> would in a project file, but the project is not signed.
// The project asks PostSharp to sign the assembly, but the C# compiler did not sign it.
// @Property(SignAssembly=True)
using System;
using PostSharp.Aspects;
using PostSharp.Serialization;
namespace Errors.PS0074_Error;
[PSerializable]
public class LogAttribute : OnMethodBoundaryAspect
{
public override void OnEntry( MethodExecutionArgs args )
{
Console.WriteLine( $"Entering {args.Method.Name}." );
}
}
public class OrderService
{
[Log]
public void PlaceOrder( string product )
{
Console.WriteLine( $"Order placed for {product}." );
}
}
public static class Program
{
public static void Main()
{
new OrderService().PlaceOrder( "Coffee" );
}
}
warning PS0074: The assembly has no public key, so PostSharp does not sign it although the SignAssembly property is true. Sign the assembly in the project, or set the SignAssembly property to false.
The assembly is woven, and the program runs, but the assembly is not signed.
Resolution
- When the assembly must be signed, sign it in the project, with the
SignAssemblyandAssemblyOriginatorKeyFileMSBuild properties. PostSharp then signs the woven assembly with the same key, and you do not need thePostSharpSignAssemblyproperty. - When the assembly does not need a strong name, remove the
PostSharpSignAssemblyproperty, or theSignAssemblyentry of thePostSharpPropertiesproperty.
In the following example, the project no longer asks PostSharp to sign the assembly.
// The project no longer asks PostSharp to sign the assembly.
using System;
using PostSharp.Aspects;
using PostSharp.Serialization;
namespace Errors.PS0074_Fixed;
[PSerializable]
public class LogAttribute : OnMethodBoundaryAspect
{
public override void OnEntry( MethodExecutionArgs args )
{
Console.WriteLine( $"Entering {args.Method.Name}." );
}
}
public class OrderService
{
[Log]
public void PlaceOrder( string product )
{
Console.WriteLine( $"Order placed for {product}." );
}
}
public static class Program
{
public static void Main()
{
new OrderService().PlaceOrder( "Coffee" );
}
}
Entering PlaceOrder.
Order placed for Coffee.
See Also
Other Resources
Well-Known MSBuild Properties
Well-Known PostSharp Properties