Nullables "Possible 'System.InvalidOperationException'"

I can't quite get what ReSharper is complaining about? Is is access to modified closures (nah?)...

public class Foo
   public int? FooValue;

public void DoBar(Foo foo)
   var e = Enumerable.Empty<int>();

   if(foo != null && foo.FooValue.HasValue)
      var values = e.First(i => i == foo.FooValue.Value); // foo.FooValue.Value is causing this

If I copy the value of foo.FooValue.Value to a local variable, theres no problem.

Could someone enlighten me?
1 comment
Comment actions Permalink

By the way, ReSharper suggest wrapping the problem with a null-check, which obviously doesn't work.


Please sign in to leave a comment.