I'm using Code Contracts to declare that a property returns a non-null, non-empty sequence of strings like so:
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'm getting a warning from Resharper as described in the code comment above.
This is similar to the question here:, but I have tried applying the fix in the answer to that question and it doesn't fix this particular issue.
Does anyone know how to fix this (other than using Resharper comments to suppress the warning)?
I'm using Resharper 7.1.2 C# Edition, build 7.1.2000.1478
(I've checked on several machines and it happens on all of them. Vanilla install of R# - we haven't modified any of its XML files other than me trying to apply the fix from the answer that I linked above.)
Further information:
I'm trying this with Visual Studio 2012 with update 2, with .Net 4.0 and .Net 4.5.
Also, you need to add the conditional compilation symbol "CONTRACTS_FULL" to the project's Build settings (in the "conditional compilation symbol" textbox).