Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xamarin.iOS - Failure to Load TimeZoneData when linking #57

Open
ibrahimmd90 opened this issue Oct 1, 2019 · 0 comments
Open

Xamarin.iOS - Failure to Load TimeZoneData when linking #57

ibrahimmd90 opened this issue Oct 1, 2019 · 0 comments

Comments

@ibrahimmd90
Copy link

A known issue in Xamarin.iOS and Xamarin.Android is that, when we enable linker (Link All), some code fails in run time. I faced this issue in my project, everything worked well using the NuGet package when Linker setting is set to "Don't Link". But after setting linker to "Link All" it raises error:

Steps to repeat the problem:
1- Create Xamarin.iOS project.
2- Call TZNames.GetDisplayNames().
3- Exception is thrown right in this line in point 2.

Newtonsoft.Json.JsonSerializationException: 'Unable to find a constructor to use for type TimeZoneNames.TimeZoneData. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. Path 'DisplayNames', line 1, position 16.'
Solution that I have done is to download the source and modify source. It was a simple solution but little bit tricky.

Steps for solution:
1- Remove NuGet Package (TimeZoneNames).
2- Download the git repository then add the project (TimeZoneNames) directly in your solution.
3- Add the following code snippet at the end of (TZNames.cs):
static public void Preserver() { new TimeZoneData(); new CldrLanguageData(); new TimeZoneSelectionData(); }
4- In the iOS project, create a static class and add this static method in it:
[Preserve(AllMembers = true)] static class Preserver { static void EnsurePreserved() { TimeZoneNames.TZNames.Preserver(); } }
5- You are done !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant