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.
using
statement or something equally asinine to makedouble
mean something other thanSystem.Double
? If you are working with source control, do a pull/refresh/whatever to make sure your local working copy is the very latest that's in the repository. – Patiodouble
is a C# type, I'm sure you cannot define a custom type with the same name. – Ingerdouble
, of all things, makes this Twilight Zone material. – Hamstringout
parameter and checking to see if the build server also misbehaves in that case? In other words, is theout
parameter issue specific todouble.TryParse
, or is it more generalized? – Muscateldouble.TryParse
in a separate library in your solution. Does it still work? Try in a brand new fresh solution with no dependencies. What aboutint.TryParse
? Does it work with your ownout
parameter methods? – Chenabtry...catch
block works, as does swapping the class in question to float. – Hamstring/t:Clean,Build
for it to force a full rebuild. DoesQueryParser.cs(449,53)
point to thatTryParse
call? Are both installed .net framework versions the same? Check if there are new windows updates for the framework that may have screwed things up. – Salespeople