Bug 31312 - App Crash on datetime.parseexact
Summary: App Crash on datetime.parseexact
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 5.2
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: marcos.henrich
URL:
Depends on:
Blocks:
 
Reported: 2015-06-23 05:44 UTC by Philippe Creytens
Modified: 2016-02-15 13:17 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and 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 Links.

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 Developer Community or GitHub 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.

Related Links:
Status:
RESOLVED NOT_REPRODUCIBLE

Description Philippe Creytens 2015-06-23 05:44:36 UTC
Hey,

Since I've updated Xamarin to the latest stable version my app crashes when I perform a ParseExact supplying null as CultureInfo. Which should refer to the default CultureInfo. When I supplly the InvariantCulture as CultureInfo the app does not crash anymore.
The error thrown was: "String was not recognized as a valid DateTime"

String format was MM/dd/yyyy HH:mm:ss

Date = DateTime.ParseExact (date, "MM/dd/yyyy HH:mm:ss", null);

Date = DateTime.ParseExact (date, "MM/dd/yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);

Xamarin Studio 5.9.3
Xamarin.Android 5.1.3.1

This does however work with an older published version of Xamarin, which is the one I used before:
Xamarin Studio 5.8.3
Xamarin.Android 4.20.1 (release 14th of april)
Comment 1 Arpit Jha 2015-07-01 01:57:27 UTC
I have checked this issue and able to reproduce with help of bug description.

Steps to reproduce that I have followed.
1.Create a Xamarin.Android app.
2.Implement following code on button click.

 string date = DateTime.Now.ToLocalTime().ToString ();

				//DateTime	Date = DateTime.ParseExact (date, "MM/dd/yyyy HH:mm:ss", null);
				DateTime	Date = DateTime.ParseExact (date, "MM/dd/yyyy HH:mm:ss",System.Globalization.CultureInfo.InvariantCulture);

3.Run the app.


I am getting a runtime exception 'System.FormatException:String was not recognised as a valid DateTime '  

Screencast: http://www.screencast.com/t/UJFzsCvI0Q

Environment Info:
=== Xamarin Studio ===

Version 5.9.4 (build 5)
Installation UUID: 3d25a767-a003-4a7d-9f5e-e57987cf6cf0
Runtime:
	Mono 4.0.2 ((detached/c99aa0c)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400020005

=== Xamarin.Android ===

Version: 5.1.4.16 (Enterprise Edition)
Android SDK: /Users/mac360_xamarin/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Apple Developer Tools ===

Xcode 6.3 (7569)
Build 6D570

=== Xamarin.iOS ===

Version: 8.10.2.39 (Enterprise Edition)
Hash: 4e8928a
Branch: master
Build date: 2015-06-29 11:03:42-0400

=== Xamarin.Mac ===

Version: 2.1.0.1160 (Enterprise Edition)

=== Build Information ===

Release ID: 509040005
Git revision: 8010a90f6e246b32364e3fb46ef2c9d1be9c9a2b
Build date: 2015-06-08 16:52:06-04
Xamarin addins: 7e93e9c3503f28770f23ce1b7eafd829919f18e8

=== Operating System ===

Mac OS X 10.10.0
Darwin mac360-xamarins-Mac-mini.local 14.0.0 Darwin Kernel Version 14.0.0
    Fri Sep 19 00:26:44 PDT 2014
    root:xnu-2782.1.97~2/RELEASE_X86_64 x86_64
Comment 2 marcos.henrich 2015-09-21 11:03:57 UTC
I was not able to reproduce this issue. The line below returned no exception in Xamarin.Android 5.1.6.7.

var date = DateTime.ParseExact ("09/21/2015 15:09:00", "MM/dd/yyyy HH:mm:ss", null);


@Philippe does the line of code above throw an exception in your device?

@Arpit DateTime.Now.ToLocalTime().ToString () returns "9/21/2015 3:36:16 PM" the "PM" makes it invalid.
Comment 3 Arpit Jha 2015-09-22 03:30:11 UTC
@marcos, I have checked this issue and observed that 

DateTime.ParseExact does not handle PM, "9/21/2015 3:36:16 PM" format of date time.

DateTime.Now.ToLocalTime().ToString (); always return date time in "9/21/2015 3:36:16 PM" format.


var date = DateTime.ParseExact ("09/21/2015 15:09:00", "MM/dd/yyyy HH:mm:ss",null); 

above line works expected , returns date time '9/21/2015 3:09:00 PM' with PM.
Comment 4 Arpit Jha 2015-09-22 03:31:32 UTC
An update to comment 3:
Environment Info:
=== Xamarin Studio ===

Version 5.9.7 (build 10)
Installation UUID: 3d25a767-a003-4a7d-9f5e-e57987cf6cf0
Runtime:
	Mono 4.0.4 ((detached/cb6d6b2)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400040002

=== Apple Developer Tools ===

Xcode 7.0 (8227)
Build 7A220

=== Xamarin.iOS ===

Version: 9.0.1.20 (Enterprise Edition)
Hash: d8e9592
Branch: master
Build date: 2015-09-18 23:22:05-0400

=== Xamarin.Android ===

Version: 5.1.6.7 (Enterprise Edition)
Android SDK: /Users/mac360_xamarin/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
		5.1    (API level 22)
Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: 2.4.0.55 (Enterprise Edition)

=== Build Information ===

Release ID: 509070010
Git revision: 4f45c78e4d931a316efa87079b128dd0aa5db951
Build date: 2015-09-17 14:49:26-04
Xamarin addins: 96968464da2a0d5a14494688c270a3ba3f8aec03

=== Operating System ===

Mac OS X 10.10.5
Darwin mac360-xamarins-Mac-mini.local 14.5.0 Darwin Kernel Version 14.5.0
    Wed Jul 29 02:26:53 PDT 2015
    root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64
Comment 5 marcos.henrich 2016-02-15 13:17:16 UTC
I was not able to reproduce an error while running:

var date = DateTime.ParseExact ("09/21/2015 15:09:00", "MM/dd/yyyy HH:mm:ss", null);

Thus I am marking this as no reproducible.

If someone is having a problem with this please let me know your use case and the versions of your Xamarin products.