Bijington
Bijington

Reputation: 3751

DateTime Parse missing on iOS device

I am trying to add a DatePicker to a Xamarin Forms project. I have lifted a sample from Xamarins website or also explained below:

<DatePicker VerticalOptions="CenterAndExpand" Date="{x:Static sys:DateTime.Now}">
    <DatePicker.Format>yyyy-MM-dd</DatePicker.Format>
    <DatePicker.MinimumDate>
        <sys:DateTime x:FactoryMethod="Parse">
            <x:Arguments>
                <x:String>Jan 1 2000</x:String>
            </x:Arguments>
        </sys:DateTime>
    </DatePicker.MinimumDate>
    <DatePicker.MaximumDate>
        <sys:DateTime x:FactoryMethod="Parse">
            <x:Arguments>
                <x:String>Dec 31 2050</x:String>
            </x:Arguments>
        </sys:DateTime>
    </DatePicker.MaximumDate>
</DatePicker>

I also have both namespaces included:

xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"

When running this on the iPhone Simulator (version 11.2) it happily renders and works however if I run it on a physical device (version 11.2) it throws the following exception:

System.MissingMemberException

No static method found for System.DateTime::Parse (System.String)

Has anyone encountered this issue or know of a reason why this would be failing?

Upvotes: 1

Views: 498

Answers (1)

Bijington
Bijington

Reputation: 3751

Just to clarify on the answer as mentioned by @Jason and @SushHangover.

The Mono linker does a static evaluation, thus non-compiled XAML is not reviewed since it would be serialised/reflection-based at runtime. Without the linker, apps would be huge and in terms of iOS Apps, those apps have to have Xamarin.iOS.dll linked to remove the features you are not using otherwise App submission would fail due to the entire iOS API being referenced without all the iOS entitlements enabled. Also explained here.

In short the quick fix was to refer to DateTime.Parse in code in order to prove the point. I shall look in to actually forcing it in the compiler when I get a chance as I don't need to call DateTime.Parse in code.

Upvotes: 1

Related Questions