I'm about ready to deploy an MVC web application that I've been tasked with managing (I did not create the application). The project is now compiling in production mode with no errors, however I have some warnings - 9 to be precise.
Now 6 are to do with the test project which is fine, however there are two that involve the Web project. these errors are:
Unreachable code detected
In both instances these warnings are thrown on the Return value, e.g.
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
if (true)
{
return new ValidationResult("Passwords don't match", new string[] { OriginalProperty });
}
return null;
}
In the above example, the "return null" line throws the unreachable code warning.
This might be a silly question (so please go easy ;-) ), but how important are these warnings to the functionality of the application? Obviously they are there for a reason, but they're not errors, so would I be relatively okay to ignore them and deploy?
Your if
condition always evaluates to true
(if (true)
) so this method is equivalent to:
protected override ValidationResult IsValid(object value,
ValidationContext validationContext)
{
return new ValidationResult("Passwords don't match",
new string[] { OriginalProperty });
}
And that's why you get the compiler warning. The last line which returns null could never be hit. As far as ignoring warnings is concerned I would recommend you to never ignore them. There are cases where a warning could lead in an unexpected behavior during runtime. Personally I've checked the option in VS which treats warnings as errors to make sure never miss a warning.