I use Code Contracts to declare that a property returns a nonempty, nonempty string sequence:
public IEnumerable<string> Filenames { get { Contract.Ensures(Contract.Result<IEnumerable<string>>() != null); // Next line gives Resharper Warning // "Possible null assignment to entity marked with 'not null' attribute": Contract.Ensures(Contract.Result<IEnumerable<string>>().Any()); return new []{"TEST"}; // Dummy data for demo purposes. } }
I get a warning from Resharper as described in the code comment above.
This is similar to the question here: but I tried to apply the fix in the answer to this question and did not fix this specific problem.
Does anyone know how to fix this (other than using Resharper comments to suppress the warning)?
I am using Resharper 7.1.2 C # Edition, build 7.1.2000.1478
(I tested several machines, and this happens on all of them. Vanilla installation R # - we did not modify any of our XML files, except for me, trying to apply the correction from the answer linked above.)
Additional Information:
I am trying this with Visual Studio 2012 update 2, with .Net 4.0 and .Net 4.5.
In addition, you need to add the CONTRACTS_FULL conditional compilation symbol to the Build project settings (in the "conditional compilation" text box).
source share