"Field is assigned, but never read" error isn't quite right, I think

I have a property with a getter method and a setter backing field. I get this error message. Although the code calculates the value and assigns it, nothing in the code gets the value. But the property IS bound to a control in xaml. So actually, it WILL be read, just not in code.

I wish I could suppress this warning as it actually isn’t true (though of course, as far as the CODE part of the project is concerned, it is).

I suppose I could do some bogus read of the property somewhere which would get rid of the error message, but that doesn’t seem like a good idea.

Am I missing something?

… time passes …

hmm… I added this to the constructor:

      EditObservationViewModel = public partial class( DBViewModel, IEditableObject )
      ...
  constructor EditObservationViewModel;
          begin
          // bogus code to avoid compiler warning
          var x := OverallBehaviorSafePercent;
          x := OverallConditionSafePercent;
          ...

I still get the error message on the two properties on the right side. I thought having that code there would get rid of the error message, but it just put it in a new spot.

So now it is in TWO spots. I have split the viewmodel that contains this code into two files that are two partial classes. Now both of them complain. Is there maybe something about them being partials that is confusing the compiler?

Here is the declaration in the first partial class:

property OverallConditionSafePercent : nullable Int32 read GetOverallConditionSafePercent write fOverallConditionSafePercent; notify;
            property OverallBehaviorSafePercent  : nullable Int32 read GetOverallBehaviorSafePercent  write fOverallBehaviorSafePercent;  notify;

Here is the other part:

  EditObservationViewModel = public partial class( DBViewModel, IEditableObject )
     private
        function CalculateOverallConditionSafePercent : nullable Int32;
        function CalculateOverallBehaviorSafePercent  : nullable Int32;
     private
        fOverallBehaviorSafePercent: nullable Int32;
        method   GetOverallBehaviorSafePercent: nullable Int32;
     private
        fOverallConditionSafePercent: nullable Int32;
        method   GetOverallConditionSafePercent: nullable Int32;

… time passes …

I tried moving the property together with the getter and backing field in the same partial class file. That didn’t help. Then I put it back the way it was and now there is no warning. I’m reloading the IDE and the solution and seeing if I can reproduce the problem.

Mark,
it seems that your properties are private and XAML can only read public properties… perhaps that explains the warning.

try making them public (or using $HIDE/Project Options), basically the compiler detects nothing ever reads them.

Patrick,

No, the property is public. I didn’t show that there, but just the backing field and the method are private.

ck,

Yes, I know the compile doesn’t detect that it is being read in the xaml, but it is. So there really shouldn’t be an warning. These are the type of warnings that I would like to be able to suppress.

I’ll have to look up what $HIDE/Project Options is.

… time passes …

Ah ha. I’ve found this documentation (for anyone else looking for it): http://old.elementswiki.com/en/Breaking_Changes

Probably there is some other newer one, but Bing found that one at least.

XAML doesn’t really read it, that uses reflection.

In any case, the value does get fetched. I’ve marked those that might show up like that with the {$HIDE H7}.

I got passed all the hundreds of errors and warnings and actually got a piece of code to run. Now I’m tracking down what I broke when I changed it to make the compiler happy. (or that was wrong before and the compiler managed to make it work)