| Severity | Error |
| Reported by | PostSharp |
| Message | Cannot load the address of the value-type field "<Field>" because an aspect removes this field. To call an instance method of the field, use the Post.GetValue method. To pass the field by reference, copy it to a local variable, pass the local variable by reference, and assign the local variable back to the field after the call [in method "<Method>"]. |
Cause
An aspect that intercepts a field, such as a LocationInterceptionAspect, turns the field into a property, and PostSharp replaces each read and each assignment of the field with a call of the getter or the setter. A reference to the field, which the C# compiler emits to change a member of a structure stored in the field, to call an instance method of this structure, or to pass the field to a ref, out or in parameter, cannot be replaced in this way.
Usually the field remains in the type, and PostSharp leaves the access by reference as it is and reports the warning PS0089. PostSharp reports the error PS0088 instead when the field is also marked for removal, because the reference would then point to a field that no longer exists. <Method> is the method that contains the access.
None of the aspects of PostSharp marks a field for removal: only an add-in written with the PostSharp SDK can, so no example can show this message.
Resolution
Change the code that accesses the field by reference in <Method>:
- To change a member of a structure stored in the field, copy the field to a local variable, change the local variable, and assign it back to the field. Better, make the structure immutable and assign a new value to the field.
- To call an instance method of the structure, pass the field to GetValue<T>(T), as in
Post.GetValue( this.location ).ToString(): the method is called on a copy of the value. - To pass the field by reference, copy it to a local variable, pass the local variable, and assign it back to the field after the call.
When you did not write the add-in that removes the field, report the problem to its author.
See Also
Reference
LocationInterceptionAspect
GetValue<T>(T)
Other Resources