Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
GitHub or Developer Community with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
Our app makes extensive use of "periods" to line up financial data on month-end. The period is the number of months since the end of Jan 1900. So the data from October 2000 is period 1209, for instance.
Under VS/.Net (3.x and on) I use this code to convert the month number back to a DateTime:
return new DateTime(1900, Period + 1, 0);
This returns the last day of the month, in this case 31 October 2000. This is a general feature of the constructor, in effect it combines DateAdd functionality so "odd" numbers will still produce useful output.
In Mono/Xamarin, it raises:
"Year, Month, and Day parameters describe an un-representable DateTime."
It appears there is some difference between the APIs.
According to referencesource,
https://github.com/Microsoft/referencesource/blob/master/mscorlib/system/datetime.cs#L173 which calls https://github.com/Microsoft/referencesource/blob/master/mscorlib/system/datetime.cs#L511 checks and validates the month, so an exception is expected
Compiling and running a sample like you provide, http://pastebin.com/U76zfQrc, throws an ArgumentOutOfRangeException for me on Windows 8 w/ .NET 3 and 4.5
.NET throws same error for code like http://pastebin.com/U76zfQrc
Unhandled Exception: System.ArgumentOutOfRangeException: Year, Month, and Day parameters describe an un-representable DateTime.
at System.DateTime.DateToTicks(Int32 year, Int32 month, Int32 day)
at System.DateTime..ctor(Int32 year, Int32 month, Int32 day)
at Program.Main(String args)
It appears this is not a Mono problem but a conversion problem. When I look at the original VB code and run it through the converter it turns into incorrect C# code. The proper call is supposed to be DateSerial, which I guess it turns into DateTime. You can close this one.