VS 2010 error "Value to add was out of range. Parameter name: value "
I am facing a weird problem. My web application throws error "Value to add was out of range Parameter name :value ". Now this is not every time I run the program.Sometimes shows error and sometimes runs without problems (no changes done).stack traces given below the error is not clear (at least for me). Anybody faced this kind of issue ?
Error Details
Value to add was out of range. Parameter name: value Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: Value to add was out of range.
Parameter name: value
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[ArgumentOutOfRangeException: Value to add was out of range.
Parameter name: value]
System.DateTime.Add(Double value, Int32 scale) +9388319
System.Web.Compilation.CodeDirectoryCompiler.GetCodeDirectoryAssembly(VirtualPath virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet excludedSubdirectories, Boolean isDirectoryAllowed) +8837703
System.Web.Compilation.BuildManager.CompileCodeDirectory(VirtualPath virtualDir, CodeDirectoryType dirType, Str开发者_如何学Pythoning assemblyName, StringSet excludedSubdirectories) +125
System.Web.Compilation.BuildManager.CompileCodeDirectories() +319
System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +248
[HttpException (0x80004005): Value to add was out of range.
Parameter name: value]
System.Web.Compilation.BuildManager.ReportTopLevelCompilationException() +62
System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +421
System.Web.Compilation.BuildManager.CallAppInitializeMethod() +31
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +605
[HttpException (0x80004005): Value to add was out of range.
Parameter name: value]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9013676
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +258
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
Just guesses: as the exception seems to be thrown from the code that you do not control, it is not your code that causes the error. However, that could be your system settings. For example, for some weird reason System.DateTime.Add(Double value, Int32 scale)
is called with such parameters, that, as MSDN states,
The resulting DateTime is less than MinValue or greater than MaxValue.
Is it ever possible that the time on your computer is now set to some incredibly high value? Close to 23:59:59.9999999, December 31, 9999
, for instance. Or maybe low value, close to 00:00:00.0000000, January 1, 0001
. So the compiler for some reasons picks up the current date and needs to add some time span to it, which causes your error.
Just a wild guess, but maybe...
UPDATE
The code of the System.Web.Compilation.CodeDirectoryCompiler.GetCodeDirectoryAssembly
method can be found here. In the code there is a line
DateTime waitLimit = DateTime.UtcNow.AddMilliseconds(3000);
That's the only place that could throw such exception (if the version I am looking at is the same as your environment). So it gives more votes for weird time set on your computer.
This can happen if the value you are trying to assign is null
. Try coalescing the value
suppose:
int i = value ?? 0; //if value is null, zero is assigned to i
MyClass _class = ValueClass ?? new MyClass(); //same as above, except it instantiates.
DateTime someDate = getChuckNorrisBirthDate() ?? DateTime.Now.Date(); // beware of chuck norris
I have seen this error with DateTime
variables.. but it was ages ago. Since you do not provide enough information about the type of variable etc (and the image is too small to make out anything) I am just guessing it on top of my head.
Issue solved. Just changed my regional settings,date/time settings in control panel to some random setting and then reverted them back to original followed by a PC restart and error is gone.Issue might be with the GetCodeDirectoryAssembly code as mentioned by @Michael Sagalovich.Will investigate for more details if the error pops up again :)
Thanks All
精彩评论