Open sandboxFocusImprove this doc

PS0209: Enhanced Constructor of Base Class Not Found

Severity Error
Reported by PostSharp
Message Cannot find the enhanced overload of the constructor "<Constructor>", which PostSharp adds to run the OnInstanceConstructed advices. Build the assembly of this constructor with the same version of PostSharp as the current project.

Cause

An OnInstanceConstructedAdvice runs once an object is fully constructed, after the constructor of the most derived class. To know which constructor is the last one, PostSharp adds to each constructor of the target class, and of the classes derived from it, an overload with an extra parameter of type ConstructorDepth, and makes the constructors of the derived classes call these overloads instead of the original constructors.

When the base class is in another assembly, PostSharp looks for the overloads that it added when it built this assembly. It reports PS0209, on the constructor of the base class, when the constructor that the derived class calls has no such overload. <Constructor> is this constructor of the base class. This happens when:

  • The assembly of the base class was built with another version of PostSharp, or modified after PostSharp built it.
  • The constructor of the derived class calls the deserialization constructor of the base class, base( info, context ) with a SerializationInfo and a StreamingContext: PostSharp adds no overload to deserialization constructors, but still redirects the call.

The first case depends on how another assembly was built, and the second one is a defect of PostSharp, so no example shows this message.

Resolution

  • Rebuild the assembly of the base class with the version of PostSharp of the current project, and make sure that the project references this build, not an older copy in a package cache or a lib folder.
  • When the constructor is a deserialization constructor, make the deserialization constructor of the derived class call another constructor of the base class, or move the derived class into the assembly of the base class, where PostSharp handles the call.

See Also

Reference

OnInstanceConstructedAdvice

Other Resources

Advice Methods