I have a library with the following code:
double result = -1;
if (!string.IsNullOrEmpty(fieldName))
{
string value = HttpContext.Current.Request.QueryString[fieldName];
if (string.IsNullOrEmpty(value))
{
value = HttpContext.Current.Request.Form[fieldName];
}
if (string.IsNullOrWhiteSpace(value) || !double.TryParse(value.Trim(), out result))
{
result = -1;
}
}
return result;
In my local copy of Visual Studio 2015 this compiles fine. Last week the build server would let this compile without a problem as well. Suddenly, on Monday the build server started having the error:
QueryParser.cs(449,53): error CS1620: Argument 2 must be passed with the 'ref' keyword [$projectPath\Core40.csproj]
When I make that switch (using ref
instead of out
), the build server is able to complete the build without errors, but Visual Studio will no longer compile.
From my reading of the relevant documentation, double.TryParse
has always taken the out
keyword, so there must be something off about the build server's libraries, but I'm not sure what or how to go about diagnosing it.
After some of the questions below, I went back to the class and confirmed that there are multiple instances of decimal.TryParse(value, out result)
, int.TryParse(value, out result)
, float.TryParse(value, out result)
, long.TryParse(value, out result)
, and Guid.TryParse(value, out result)
. I also was able to replace "double" with "float", and it worked just fine. This is something specific to double
.
Apparently, the build command is:
msbuild /m /p:Configuration=Release /p:Platform="Any CPU" $path\$solution.sln
Also, I can replace the TryParse
with a try { return double.Parse(value); } catch (Exception) { return DEFAUlT; }
block (my temporary way forward), but that doesn't actually solve the problem.
Turns out that this was some type of bad cache issue. Eventually, DevOps rebooted the build machine and the problem went away. I'd love to have an actual root cause, but the resolution was still "turning off and turning it on again."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With