c# - VS 2010错误 "Value to add was out of range. Parameter name: value "

标签 c# visual-studio-2010

我遇到了一个奇怪的问题。我的 Web 应用程序抛出错误“要添加的值超出参数名称:值的范围”。现在,这不是我每次运行程序时都会出现的情况。有时会显示错误,有时运行时没有问题(未进行任何更改)。下面给出的错误堆栈跟踪不清楚(至少对我来说)。有人遇到过这样的问题吗?

错误详细信息

要添加的值超出范围。 参数名称:值 描述:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。

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, String 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 

enter image description here

最佳答案

只是猜测:由于异常似乎是从您无法控制的代码中引发的,因此不是您的代码导致了错误。但是,这可能是您的系统设置。例如,由于某些奇怪的原因 System.DateTime.Add(Double value, Int32 scale) 被使用这样的参数调用,如 MSDN states ,

The resulting DateTime is less than MinValue or greater than MaxValue.

您的计算机上的时间现在是否有可能被设置为某个令人难以置信的高值?例如,接近 23:59:59.9999999, December 31, 9999。或者可能是低值,接近 00:00:00.0000000, January 1, 0001。因此,编译器出于某种原因会选择当前日期并需要为其添加一些时间跨度,这会导致错误。

只是一个疯狂的猜测,但也许......

更新

可以找到System.Web.Compilation.CodeDirectoryCompiler.GetCodeDirectoryAssembly方法的代码here 。代码中有一行

DateTime waitLimit = DateTime.UtcNow.AddMilliseconds(3000); 

这是唯一可能引发此类异常的地方(如果我正在查看的版本与您的环境相同)。因此,它会为您计算机上设置的奇怪时间提供更多投票。

关于c# - VS 2010错误 "Value to add was out of range. Parameter name: value ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6925322/

相关文章:

c# - 如何在 C# 中从图像流传输视频流

.net - Web 部署包与 MSI 部署

visual-studio-2010 - 在不添加引用的情况下通过预构建事件构建另一个项目

visual-studio - Visual Studio - 如何在不接触鼠标的情况下使用它?

c++ - 运行选项从 Microsoft Visual C++ 2010 消失

c# - HashHelpers.GetPrime 中这一行的目的是什么?

C#检测光标是否隐藏

c# - 无法将 null 添加到可空列表

visual-studio-2010 - VS2010中控制台项目的命令行参数中的项目路径或其他宏

c# - 如何在业务层实现审计