Select to view content in your preferred language

Date fields subtract a month from the date, resulting in Exception

5274
8
09-15-2011 08:16 AM
BrianSodano
Emerging Contributor
FileGeodatabase API v1.1 via .NET wrapper:

All Date fields from any File Geodatabase come out subtracting a month from the date.  For example:

The date 6/20/2007 8:59:22 AM will be returned as 5/20/2007 8:59:22 AM

Additionally, dates such as 7/31/2007 8:59:22 AM being converted to an impossible 6/31/2007 8:59:22 AM, or any date in January will return a "A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll. General exception. Year, Month, and Day parameters describe an un-representable DateTime."

I am assuming this to be a bug in the .NET wrapper for the 1.1 API - I've confirmed this is only occurring in the .NET wrapper. The date field returns correctly when operating only within the C++ API without the .NET wrapper.  Additionally confirmed this error occurs with both the x86 and x64 compiled binaries for the .NET wrapper for the API.

Stack Trace:

at System.DateTime.DateToTicks(Int32 year, Int32 month, Int32 day)
at Esri.FileGDB.Row.GetDate(String field) in f:\filegdb_api\src\esri.filegdbapi\row.cpp:line 190
at Esri.FileGDB.Row.get_Item(String field) in f:\filegdb_api\src\esri.filegdbapi\row.cpp:line 390
at MyProject.MainWindow.SelectAllColumns() in C:\pathtoproject\MyProject\MainWindow.xaml.cs:line 239

Currently, I can convert dates I can read and unfortunately just swallow errors for dates that cause an issue:

                                            try
                                            {
                                                data = row.GetDate(fieldName);
                                                //bug in 1.1 API in .NET wrapper
                                                data = ((DateTime)data).AddMonths(1);
                                            }
                                            catch (SystemException ex)
                                            {
                                                Trace.WriteLine(ex);
                                            }

Any ideas for a workaround or how best to potentially log this as a bug?  Thanks.
0 Kudos
8 Replies
BrianSodano
Emerging Contributor
I've confirmed this is only occurring in the .NET wrapper. The date field returns correctly when operating only within the C++ API without the .NET wrapper.
0 Kudos
BrianSodano
Emerging Contributor
Stack Trace:

   at System.DateTime.DateToTicks(Int32 year, Int32 month, Int32 day)
   at Esri.FileGDB.Row.GetDate(String field) in f:\filegdb_api\src\esri.filegdbapi\row.cpp:line 190
   at Esri.FileGDB.Row.get_Item(String field) in f:\filegdb_api\src\esri.filegdbapi\row.cpp:line 390
   at MyProject.MainWindow.SelectAllColumns() in C:\pathtoproject\MyProject\MainWindow.xaml.cs:line 239
0 Kudos
BrianSodano
Emerging Contributor
Additionally confirmed this error occurs with both the x86 and x64 compiled binaries for the .NET wrapper for the API.
0 Kudos
BrianSodano
Emerging Contributor
no ideas / comments?
0 Kudos
LanceShipman
Esri Regular Contributor
I'm reviewing this issue for a workaround. I'll post a bug number shortly.
0 Kudos
BrianSodano
Emerging Contributor
Thanks for the update. Without recreating decent pieces of the existing wrapper in C++/CLI OR creating my own wrapper for just this (easier) and making dual calls to the FGDB, creating a workaround/patch is proving to be a challenge.  Reflection proved that error handling is a bit scarce for these types of conversions - can a future suggestion be to return the field value as System.Object "just in case" as an alternative?  Rather than an in-line conversion.  That way, oddball conversions can be handled more dynamically in .NET?

Let me know if you have ideas for a workaround.

Brian
0 Kudos
LanceShipman
Esri Regular Contributor
I've entered this issue as NIM072876.
0 Kudos
BrianSodano
Emerging Contributor
Lance,

Is there any place users like me can view outstanding issues?

Also, any word on timelines for a fix for this or other issues?

Thanks,

Brian
0 Kudos