DependencyService.Get returns null when setting is "Link All"

Viewed 167

My Xamarin.iOS app (Xamarin.Forms) runs fine as long as I have the iOS project's properties -> iOS Build -> Linker Behavior set to "Don't Link" or "Link Framework SDKs only". But when it's set to "Link All" - DependencyService.Get<ISomething>(); returns null.

Why is that? / How do I fix that?

1 Answers

the Linker can't tell that a class you only instantiate via DI is actually being used. To get around that, add the Preserve attribute to your class

[Preserve (AllMembers = true)]
Related