I am running FxCop against my Silverlight code and appear to be getting a lot of CA1051 error codes:
Error, Certainty 90, for DoNotDeclareVisibleInstanceFields
Target : #msgTextBox (IntrospectionTargetMember)
Resolution : "Because field 'MessagingControl.msgTextBox' is
visible outside of its declaring type, change its accessibility
to private and add a property, with the same accessibility
as the field has currently, to provide access to it."
Help : http://msdn.microsoft.com/library/ms182141(VS.100).aspx (String)
Category : Microsoft.Design (String)
CheckId : CA1051 (String)
RuleFile : Design Rules (String)
Info : "Instance fields that are visible outside of the type
that declares them, limit your ability to change the
implementation details for those data items. Use properties
instead. They do not compromise usability or performance
and they do provide flexibility in that they conceal
the implementation details of the underlying data."
Created : 25/11/2011 10:59:54 (DateTime)
LastSeen : 25/11/2011 14:57:49 (DateTime)
Status : Active (MessageStatus)
Fix Category : NonBreaking (FixCategories)
Most of these seem to be from x:Name in the xaml so I don’t think it can be fixed? Is there anything I can do to fix these errors apart from suppressing them all?
The default visibility for control fields is set to internal.
use
x:FieldModifier="<modifier>"e.g.<TextBox x:Name="msgTextBox" x:FieldModifier="private" />to control this behavior.