One of the nice things about Visual Studio 2012 is the Code Analysis. It’s worth doing to try and find underlying problems and I found some in mine. The code worked fine, but Code Analysis told me I was doing naughties with a Virtual Method in a constructor.

Mea culpa. I was indeed. I’d created a View object with my Subclassed View in a CustomViewController.

        public override void ViewDidLoad()
            View = new MainView(UIScreen.MainScreen.Bounds);

But I’d been doing all sorts in the MainView() constructor that needed not to be there, though it had seemed to run ok. If configuration data is absent I want to stop things and have it entered. So I was creating SubViews (Controls) and then calling the UIView.AddSubView() that MainView inherited from within the Constructor. Shock Horror Probe! Bad Code Alert…

The risk is that a virtual method may not have been correctly assigned and the compiler doesn’t really like Constructors in C# to have to worry about this. After a Constructor has finished, things should be just swell.

The trick is to move the code into a subclassed ViewController.ViewWillAppear(). This is called whenever the View is about to appear. Use a bool variable to let things that should be initialized here just the once be only called just the once.

        public override void ViewWillAppear(bool animated)
            if ((View as MainView).ConfigCheck() && OneOff)
                OneOff = false;
                // one off code here

This is on Windows 7 and happens every day if I don’t start the Xamarin Bonjour service before Visual Studio and opening a Xamarin.iOS project. It’s not that big a deal but something must be switching the Xamarin Bonjour Service from Automatic. I set it to automatic a few times but it gets reset to Manual. Once it’s running it stays running for the rest of the day.


If you get this make sure the Bonjour Service is running. If it’s not, open the services MMC. You can do this from Task Manager but make sure on the Processes tab you click the Show processes from all users button as the service may not start. Then on the services Tab in Task Manager, at the bottom right then when the Services MMC opens scroll to the bottom. If you don’t see Started then right click on the service and click Start.


Hopefully you should be able to select iPhone 6.1 in the combo box and all will be well. If not see this tip on Visual Studio to Mac Connectivity.

It’s not that difficult but there’s not an awful lot about it. I haven’t tried it with .MP3 files but what I’ve done works with .wav.

First create a project folder containing the sound files. Each file should be set to Content in the property/build Action.


Then define AvAudioPlayer to play the file. I created three in the class:

public static AVAudioPlayer [] player = new AVAudioPlayer[3];
private static int playIndex {get;set;}
       public static void PlaySound(string filename)
            if (playIndex == 3)
                playIndex = 0;
            if (player[playIndex] != null)
                var file = Path.Combine("sounds", filename);
                var Soundurl = NSUrl.FromFilename(file);
                player[playIndex] = AVAudioPlayer.FromUrl(Soundurl);
                var onePlay = player[playIndex];
                onePlay.CurrentTime = onePlay.Duration*2;
                onePlay.NumberOfLoops = 1;
                onePlay.Volume = 1.0f;
                onePlay.FinishedPlaying += DidFinishPlaying;
            catch (Exception e)
                LogLine("PlaySound: Error: " + e.Message, true);

        public static void DidFinishPlaying(object sender , AVStatusEventArgs e)
            if (e.Status)
                // your code


The playIndex int variable tracks which is the next AvAudioPlayer to be used. Note that the file must specify the directory used – my files are in sounds. The player[] variables exist at the class level not locally because you don’t want the garbage collector to zap them once it exits the PlaySound method.

The AVAudioPlayer.FinishedPlaying event handler (delegate in Apple’s terms) lets you catch when it finishes playing. The AvStatusEventArgs.Status is a bool indicating if it has finished.

Because in my App, two possibly three sounds could play simultaneously, I used three AvAudioPlayers. Without them, you have to stop the current sound playing.

It pops up a dialog saying do you want to update your help and if you view the Output then 447MB later of downloads (on the Mac), it starts updating. But next time you run Visual Studio the same thing happens?

It’s not you, it’s the version of the help is 6.0 even though you are on 6.1 (according to the Xamarin Bug Log).  The quick fix is to download the help manually.  As Xamarin engineer Jose Miguel Torres say in the bug report:

“Open XCOde and go to Xcode menu –> Preferences… Then click on Downloads tab and switch from components to Documentation.There should be the iOS 6.1 DocSet entry and the most probably is that it is not installed. Click on Check and Install button from the Xcode dialog and wait for the iOS 6.1 DocSet to be installed. ”


After that, you should see the Mac Server Log

[2013-09-01 10:22:44.2] Using
[2013-09-01 10:22:44.9] API Docs installed version:
[2013-09-01 10:22:44.9] API Docs official version:
[2013-09-01 10:22:44.9] Command [StatusSdk: CommmandUrl=StatusSdk] finished (9)

No more update requests.

This isn’t meant to start a flame war. I’m an experienced C# developer (at work plus I wrote the About C,C++ and C# website from 2006-2013) and during those years I tried to learn Objective-C. I knew C, understood the Obj-C memory management (pre ARC), about retaining memory etc and understood the message passing with [].

What I found hard though was seeing the big picture (View Controllers and Views) to structuring Apps as well as learn Obj-C at the same time. So I looked at it then worked my way through some open source games. One thing jumped out- the number of files needed was considerable, just like Java one per class only with Obj-C it was a .m and .h file per class!

Then there was Xcode 3 and Interface Builder. I’d grew up with Delphi and then C# so a GUI that let you hook up code to form objects was intuitive and in Obj-C it was somewhat painful jumping from Xcode to IB and then back.

You still get that with Xamarin if you create Apps with Nibs. So far I’ve done everything in code, walking down the nibless route. Xamarin have a new tool somewhere in alpha that generates C# code so fingers crossed, one of these days it’ll emerge blinking into the sunlight.

I’ve spent several years using Visual Studio: all versions from 2003, 2005, 2008, 2010 and 2012 so it’s a comfy home for me and to be able to step through an iPhone App in the VS debugger is very clever and executes faster than I expected. Between the iPhone and my PC is a network with a Mac Mini that proxies I guess the debug data between phone and PC.

But you don’t get it cheap- Visual Studio support in Xamarin is $999 and they expect you to pay that each year for support. You don’t have to of course but you won’t get the upgrades and with an new iOs version each year…

So out of the blue the offer of paid work to convert a Windows Phone App to iPhone with a down payment that bought Xamarin; that’s why I became a Xamarin developer.