Open sandboxFocusImprove this doc

PS0201: Type Named in XML Configuration Not Found

Severity Error
Reported by PostSharp
Message Cannot find the type '<TypeName>' that this XML element names. Check the name of the element and the clr-namespace and assembly of its XML namespace.

Cause

Some elements of a postsharp.config file contain CLR objects written in XML: the children of the Multicast element, which add aspects to the project, and the content of the Logging element, which configures the logging profiles. The name of such an element is the name of the class, with or without its Attribute suffix, and its XML namespace gives the .NET namespace and the assembly of the class, in the form clr-namespace:Namespace;assembly:Assembly. See Including CLR Objects in Configuration.

PostSharp reports PS0201 when no class with this name exists in this namespace and assembly. <TypeName> is the full name that PostSharp looked for, with the assembly. The location of the message is the XML element. The usual causes are:

  • The class was renamed or moved to another namespace, and the configuration file was not updated.
  • The name of the element is misspelled.
  • The clr-namespace or the assembly of the XML namespace is wrong, for example the name of the project instead of the name of the assembly, or the assembly is not referenced by the project.

In the following example, the aspect class was renamed from LogAttribute to TraceAttribute, but postsharp.config still names LogAttribute.

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.postsharp.org/1.0/configuration">
  <Multicast xmlns:my="clr-namespace:Errors.PS0201_Error;assembly:PS0201_Error">
    <!-- The aspect class was renamed to TraceAttribute, but the element still names LogAttribute. -->
    <my:LogAttribute AttributeTargetTypes="Errors.PS0201_Error.OrderService" AttributeTargetMembers="PlaceOrder" />
  </Multicast>
</Project>
using System;
using PostSharp.Aspects;
using PostSharp.Serialization;

namespace Errors.PS0201_Error;

// postsharp.config applies this aspect to OrderService.PlaceOrder. The class was formerly named LogAttribute.
[PSerializable]
public class TraceAttribute : OnMethodBoundaryAspect
{
    public override void OnEntry( MethodExecutionArgs args )
    {
        Console.WriteLine( $"Entering {args.Method.Name}." );
    }
}

public class OrderService
{
    public void PlaceOrder( string product )
    {
        Console.WriteLine( $"Order placed for {product}." );
    }
}

public static class Program
{
    public static void Main()
    {
        new OrderService().PlaceOrder( "Coffee" );
    }
}
error PS0201: postsharp.config(5,6): Cannot find the type 'Errors.PS0201_Error.LogAttribute, PS0201_Error, Culture=neutral, Context=Reference' that this XML element names. Check the name of the element and the clr-namespace and assembly of its XML namespace.

Resolution

  • Make the name of the element the name of the class, with or without its Attribute suffix.
  • Make the clr-namespace of the XML namespace the namespace of the class, and its assembly the name of the assembly that declares the class, without extension. When the class is in another assembly, make sure that the project references it.

In the following example, the element names TraceAttribute.

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.postsharp.org/1.0/configuration">
  <Multicast xmlns:my="clr-namespace:Errors.PS0201_Fixed;assembly:PS0201_Fixed">
    <!-- The element names the current class of the aspect. -->
    <my:TraceAttribute AttributeTargetTypes="Errors.PS0201_Fixed.OrderService" AttributeTargetMembers="PlaceOrder" />
  </Multicast>
</Project>
using System;
using PostSharp.Aspects;
using PostSharp.Serialization;

namespace Errors.PS0201_Fixed;

// postsharp.config applies this aspect to OrderService.PlaceOrder. The class was formerly named LogAttribute.
[PSerializable]
public class TraceAttribute : OnMethodBoundaryAspect
{
    public override void OnEntry( MethodExecutionArgs args )
    {
        Console.WriteLine( $"Entering {args.Method.Name}." );
    }
}

public class OrderService
{
    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

Adding Aspects Using XML
Including CLR Objects in Configuration
Configuring Projects Using postsharp.config