| Severity | Error |
| Reported by | PostSharp |
| Message | The project could not be initialized because of the previous errors. |
Cause
Before it processes an assembly, the PostSharp compiler sets up the project: it instantiates the services and the tasks that the configuration files, such as postsharp.config or a .psproj file, and the plug-ins define, and reads the attributes of each task. When the build has reported an error by the end of this setup, PostSharp reports PS0084, which stops the build.
PS0084 is a consequence: the cause is in the errors that PostSharp reports with it. The common ones come from a Tasks section of a configuration file:
- PS0079: an element names a task that no plug-in defines.
- PS0082: an element does not set an attribute that the task requires.
- PS0075: the
Compileelement setsSignAssemblywithout a private key.
In the following example, the postsharp.config file next to the program configures a task that does not exist, so PostSharp reports PS0079 and then PS0084.
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.postsharp.org/1.0/configuration">
<Tasks>
<!-- No plug-in defines a task named Minify. -->
<Minify />
</Tasks>
</Project>
using System;
using PostSharp.Aspects;
using PostSharp.Serialization;
namespace Errors.PS0084_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" );
}
}
error PS0084: The project could not be initialized because of the previous errors.
error PS0079: postsharp.config(5,6): The task "Minify" is not defined. Check the name of the element, or add the plug-in that defines the task.
Resolution
Fix the other errors of the build, starting with the first one, as the article of each message describes. PS0084 disappears with them. When the errors come from a Tasks section that you do not need, remove the section: PostSharp configures its tasks itself.
In the following example, the element of the undefined task is removed.
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.postsharp.org/1.0/configuration">
<!-- The element of the undefined task is removed. -->
</Project>
using System;
using PostSharp.Aspects;
using PostSharp.Serialization;
namespace Errors.PS0084_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
Configuring Projects Using postsharp.config
Configuration File Schema Reference