Steps to reproduce:
I'm on 10.15 Beta (19A558d) of Catalina and using the latest XCode 11 GM 2
Installed:
https://gist.github.com/chamons/12b3c334e3add1a85a0cbf301a3eb354
Archive.zip
msbuild2.binlog.zip
Originally https://devdiv.visualstudio.com/DevDiv/_workitems/edit/985030
It looks like this is related to linking.
I tested this on xCode 10/Mojave/vs mac 8.2 and was able to recreate against a simulator by turning on SDKONLY for the linking
Though from previous conversations I thought that if something inherited from NSObject then it wouldn't get linked out?
https://xamarinhq.slack.com/archives/C03CCJNR7/p1567818035412800
I guess UISegmentedControl is one of the special ones that will get linked out?
There's nothing _using_ UISegmentedControl in a way that makes any of the assemblies metadata refer to the type - so the linker will remove it.
If you add
[assembly: Preserve (typeof (UISegmentedControl), AllMembers = true)]
to AppDelegate.cs then it will work just fine.
Though from previous conversations I thought that if something inherited from NSObject then it wouldn't get linked out?
My bad, I was not precise enough :)
User (as in _non-SDK_) types that subclass an NSObject derived type won't be removed. I need to dig out the reasons (iirc that's for NIB/storyboard instantiation - at least _partially_: there might be other reasons I forgot about).
Framework (SDK) types are handled differently - since most of them subclasses NSObject and would make the linker largely useless.
side note: I don't know enough about XF builds (so take this with a grain, or two, of salt) but...
Since you're processing the xaml file you could, in theory, detect the types that are present there, like UISegmentedControl and generate/update some code behind file that would just include a bun of lines like:
[assembly: Preserve (typeof (UISegmentedControl), AllMembers = true)]
That requires processing the .xaml before compiling the application code.
An alternative could be to generate an XML file to give the linker and, thru msbuild magic, ensure the MTouchTask gets the information. That could be done after csc has compiled all the code.