C# 应用程序中异常的含义:“不是合法的 OleAut 日期”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/310700/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Meaning of exception in C# app: "Not a legal OleAut date"?
提问by leora
Does anyone know what this means. Getting this in C# winforms applications:
有谁知道这是什么意思。在 C# winforms 应用程序中得到这个:
Not a legal OleAut date
不是合法的 OleAut 日期
采纳答案by xyz
It means that somewhere in the program is attempting to convert to or from an OLE Automation Date outside the valid range 1-January-4713 BC to 31-December-9999 AD. It might have slipped through because OLE Automation Dates are represented as a double.
这意味着程序中的某处正在尝试与有效范围 1-January-4713 BC 到 31-December-9999 AD 之外的 OLE 自动化日期进行转换。它可能已被忽略,因为 OLE 自动化日期表示为double。
Start by looking for any uses of the methods:
首先寻找这些方法的任何用途:
回答by Robert Gamble
It means you provided an invalid date somewhere, attempting to convert to or from an OLE Automation date outside the valid range 1-January-4713 BC to 31-December-9999 AD. A possible cause is that it might have slipped through because OLE Automation Dates are represented as a double.
这意味着您在某处提供了无效日期,试图在有效范围 1-January-4713 BC 到 31-December-9999 AD 之外的 OLE 自动化日期进行转换。一个可能的原因是它可能被忽略了,因为 OLE 自动化日期表示为双精度值。
回答by bugmagnet
Others have struggled with this. I suggest looking at these threads on DotNetNukeand DevShed.
其他人一直在努力解决这个问题。我建议在DotNetNuke和DevShed上查看这些线程。
回答by Joe
An OADate is represented as a double value whose value is the number of days from midnight on 30 december 1899 (negative values representing earlier dates).
OADate 表示为 double 值,其值是从 1899 年 12 月 30 日午夜算起的天数(负值表示较早的日期)。
This exception is thrown when trying to convert a value that is outside the valid range of Ole Automation dates to/from a .NET DateTime value (methods DateTime.FromOADate and DateTime.ToOADate - which are also used implicitly for COM Interop).
尝试将 Ole Automation 日期有效范围之外的值转换为 .NET DateTime 值(方法 DateTime.FromOADate 和 DateTime.ToOADate - 它们也隐式用于 COM Interop)时会引发此异常。
I believe to be valid for conversion to an OADate the .NET DateTime value needs to be strictly greater than 01/01/0100.
我认为对于转换为 OADate 有效,.NET DateTime 值需要严格大于 01/01/0100。
To convert from OADate to a .NET DateTime value, the double value needs to be strictly greater than -657435 (= 01/01/0100) and strictly less than 2958466.0 (01/01/10000).
要将 OADate 转换为 .NET DateTime 值,double 值需要严格大于 -657435 (= 01/01/0100) 并严格小于 2958466.0 (01/01/10000)。
回答by lc.
I've used:
我用过:
try
{
if (folderItem.ModifyDate.Year != 1899)
{
this.FileModifiedDate = folderItem.ModifyDate.ToShortDateString() +
" " +
folderItem.ModifyDate.ToLongTimeString();
}
}
//we need this because it throws an exception if it's an invalid date...
catch (ArgumentException) { }
to deal with the same problem I'm having. It throws the exception when we check the year in my case. Doing nothing on an invalid date is exactly the behavior I want, so this hack works.
处理我遇到的同样问题。在我的情况下,当我们检查年份时,它会抛出异常。在无效日期不做任何事情正是我想要的行为,所以这个 hack 有效。
回答by warren caulton
What I found was that a column with a large row_id '257381195' was attempting to be read by Excel as a Date. What I ended up doing was altering that column's data to a string by preceding the row_id with a single quote. This resolved my issue. Hope this helps.
我发现有一个大 row_id '257381195' 的列试图被 Excel 作为日期读取。我最终做的是通过在 row_id 前面加上单引号将该列的数据更改为字符串。这解决了我的问题。希望这可以帮助。