I’ve been converting a major App and the Migrate tool works very well but I found a couple of cases, which either it didn’t do or I messed up.

The first is when using a nint as an index in a List. It doesn’t work, as the .NET generics know nothing about nints. So just cast it to an int like this below where _itemsList is a List

Text = _itemsList[(int)row];

Converting NSDate to System.DateTime and vice versa

It’s now a compile error to assign a DateTime to a NSDate or vice versa, the implicit conversion no longer works. I think this is to highlight a subtle bug to do with NSDate is always an UTC time and DateTime is default set to DateTimeKind.Unspecified (when read from database) or DateTimeKind.Locale (when set with DateTime.Today) Source is this stackoverflow answer.

Thankfully the Foundation.NSDate class includes two explicit operators that do the job for you.
NSDate in Xamarin Object Browser


So this works.

            NSDate nDate = (NSDate) DateTime.Now;
            DateTime dDate = (DateTime) nDate;

AVAudioRecorder Changes

The settings used to create an AVAudioRecorder have changed from a NSDictionary to AudioSettings, and the AVAudioRecorder.ToUrl method no longer exists.

Instead create avsettings like this and use the factory method Create to create the AVAudioRecorder.

//Set Settings with the Values and Keys to create the NSDictionary
            avsettings = new AudioSettings(NSDictionary.FromObjectsAndKeys(values, keys));

//Set recorder parameters
            recorder = AVAudioRecorder.Create(url, avsettings, out error);

Leave a Reply

Post Navigation