Bug 8038 - FileInfo.CreationTime is wrong binding
Summary: FileInfo.CreationTime is wrong binding
Status: RESOLVED DUPLICATE of bug 6118
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 6.0.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2012-10-29 05:01 UTC by tome
Modified: 2012-10-29 09:45 UTC (History)
2 users (show)

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:

Description tome 2012-10-29 05:01:25 UTC
FileInfo.CreationTime is not correct binding to NSFileCreationDate.
Please check following test case.
It seems that the value of NSFileModificationDate affects to FileInfo.CreationTime getter.
And the setter does not work.

public void FileTimeTest ()
	NSFileManager fmgr = new NSFileManager ();
	string path = Path.GetTempFileName ();
	try {
		NSFileAttributes fattr0 = fmgr.GetAttributes (path);
		var finfo0 = new FileInfo (path);

		var nsctime0 = (DateTime)fattr0.CreationDate;
		var nsmtime0 = (DateTime)fattr0.ModificationDate;

		var ctime0 = finfo0.CreationTimeUtc;
		var mtime0 = finfo0.LastWriteTimeUtc;

		Console.WriteLine ("fattr ctime={0} mtime={1}", nsctime0, nsmtime0);
		Console.WriteLine ("finfo ctime={0} mtime={1}", ctime0, mtime0);

		Assert.AreEqual (nsctime0, ctime0);
		Assert.AreEqual (nsmtime0, mtime0);

		// Set filetime
		NSDate epoch = NSDate.FromTimeIntervalSince1970 (0);
		NSDate epochPlusOneSec = NSDate.FromTimeIntervalSince1970 (1);

		// CreationTime setter doesn't work
		//finfo0.CreationTimeUtc = (DateTime)epoch;
		//finfo0.Refresh ();
		//Assert.AreEqual ((DateTime)epoch, finfo0.CreationTimeUtc); // FAILS

		var dict = NSDictionary.FromObjectsAndKeys (
			new NSObject[] { epoch, epochPlusOneSec }
			, new NSObject[] { NSFileManager.CreationDate, NSFileManager.ModificationDate }
		NSError outError = null;
		if (!fmgr.SetAttributes (dict, path, out outError))
			AssertFail ("Could not set filetime:" + outError);

		var fattr1 = fmgr.GetAttributes (path);

		var nsctime1 = (DateTime)fattr1.CreationDate;
		var nsmtime1 = (DateTime)fattr1.ModificationDate;

		Assert.AreEqual ((DateTime)epoch, nsctime1);
		Assert.AreEqual ((DateTime)epochPlusOneSec, nsmtime1);

		var finfo1 = new FileInfo (path);
		var ctime1 = finfo1.CreationTimeUtc; // unexpectedly, returns equal to epochPlusOneSec
		var mtime1 = finfo1.LastWriteTimeUtc;

		Console.WriteLine ("fattr ctime={0} mtime={1}", nsctime1, nsmtime1);
		Console.WriteLine ("finfo ctime={0} mtime={1}", ctime1, mtime1);

		Assert.AreEqual (nsctime1, ctime1); // FAILS
		Assert.AreEqual (nsmtime1, mtime1);
	finally {
		if (File.Exists (path))
			File.Delete (path);
Comment 1 Sebastien Pouliot 2012-10-29 09:45:41 UTC
There's no "code" relation (or bindings) between FileInfo.CreationTime and NSFileCreationDate. 

Mono[Touch]'s iolayer is providing the information from the file system (a step lower than NSFileCreationDate). Right now the runtime (iolayer) does not support the HFS file system extra attributes, which is why you get different result.

This is a known issue, bug #6118.

*** This bug has been marked as a duplicate of bug 6118 ***