Mvvmlight and Xamarin.iOS cannot find ctor by default

I have a project that works fine on Android and WinPhone 8. When I try to run iOS, I get the following error

Microsoft.Practices.ServiceLocation.ActivationException: Failed to register: No public constructor found in x

where x is that SimpleIoc.Default.Register<T, TU>(); happens to flow. I moved the code around (as suggested elsewhere) to ensure that all SimpleIoc calls are SimpleIoc on the platform in ViewModelLocator .

I added the public ctors settings in the classes that complain about the error (I installed the PreferredConstructor in the source, not the recently added public ctor).

I have the feeling that this error is false positive (something else does not work, but points to this code).

Using Xam.iOS through the build server (code comes from VS2015). Xcode uses 8.3 emulators (it may be necessary to upgrade to update 8.4)

+5
source share
2 answers

Linker may be optimizing the constructor if it considers it to be unused. Try setting the linker options to Do Not Link and see if it will be back again, or even a new instance of the class elsewhere so that Linker knows that the constructor is being used. You do not necessarily want to leave it that way, but if it fixes the error, you will at least find out the reason.

+2
source

The [Save] attribute helped. Decorate it with a constructor and save the linker settings.

This attribute is part of the Microsoft.WindowsAzure.MobileServices namespace.

0
source

All Articles