Open sandboxFocusImprove this doc

PS0156: Service Type Does Not Implement IService

Severity Error
Reported by PostSharp
Message The type '<TypeName>, <AssemblyFile>' does not implement the IService interface.

Cause

The Service element of a PostSharp configuration file, such as postsharp.config, registers a build-time service: PostSharp creates an instance of the class that TypeName names, in the assembly that AssemblyFile names or, when AssemblyFile is omitted, in the assembly being built. The class must implement IService. PS0156 is meant to report a class that does not implement it. <AssemblyFile> is empty when the element has no AssemblyFile attribute.

In the current version of PostSharp, this check is not reached: when the class does not implement IService, PostSharp fails with an unhandled ArgumentNullException in TaskCollection.AddService instead of reporting PS0156. Because PostSharp crashes before it can report this message, no example can show it.

The following postsharp.config file shows the scenario, where the OrderAuditService class does not implement IService:

<Project xmlns="http://schemas.postsharp.org/1.0/configuration">
  <Service TypeName="MyApp.OrderAuditService" />
</Project>

Resolution

  • Make the class implement IService, and give it a parameterless constructor.
  • When the Service element names the wrong class, correct its TypeName attribute: it is the full name of the class, with its namespace.
  • When the class is not meant to be a service, remove the Service element.

When the build fails with Value cannot be null. (Parameter 'key') and a stack trace through TaskCollection.AddService, check the classes that the Service elements of your configuration files name.

See Also

Reference

IService

Other Resources

Configuration File Schema Reference
Configuring Projects Using postsharp.config