Open sandboxFocusImprove this doc

PS0070: Field Marked for Removal Is Initialized Before the Base Constructor

Severity Error
Reported by PostSharp
Message Cannot weave the initialization of the field <Type>.<Field>, because it is initialized before the base constructor is called, for example by a field initializer. Because the field has been marked for removal, this initialization cannot be left unwoven.

Cause

When an aspect intercepts a field, for example a LocationInterceptionAspect, PostSharp redirects every access to the field to the code of the aspect. PostSharp does not redirect the assignments that happen in a constructor before the base constructor is called, because the aspect cannot run on an object that is not initialized yet: these assignments come from the field initializers of the class, such as private int count = 1;. They keep writing to the field directly.

This is not possible when the field is marked for removal, because the field no longer exists in the woven assembly. PostSharp then reports PS0070 on the assignment. <Type> is the name of the type that declares the field, and <Field> is the name of the field.

PostSharp itself never marks a field for removal: only an add-in written with the PostSharp SDK can do it. So no example can show this message.

Resolution

  • Remove the field initializer, and assign the field in the body of the constructor instead, after the call to the base constructor.
  • Otherwise, ask the vendor of the add-in that removes the field.

See Also

Reference

LocationInterceptionAspect