Xamarin-macios: Position 103:18. Type ios:UISegmentedControl not found in xmlns clr-namespace:UIKit;assembly=Xamarin.iOS;targetPlatform=iOS with iOS 13

Created on 18 Sep 2019  路  3Comments  路  Source: xamarin/xamarin-macios

Steps to reproduce:

  1. Download the Archive.zip project
  2. set Xappy.iOS as startup project
  3. Deploy application to a device.
    a. I'm deploying this to an iPad (6th Generation) running 13.1 not sure if the exception is specific to that device or if it will show up on other devices as well

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

iOS question

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cwensley picture cwensley  路  3Comments

orryverducci picture orryverducci  路  4Comments

chamons picture chamons  路  4Comments

whitneyschmidt picture whitneyschmidt  路  3Comments

juepiezhongren picture juepiezhongren  路  3Comments