Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mvvmlight and Xamarin.iOS unable to find default ctor

I have a project that is running fine on Android and WinPhone 8. When I attempt to run on iOS, I've getting the following error

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

where x is whatever SimpleIoc.Default.Register<T, TU>(); the flow hits first. I've moved the code around (as suggested elsewhere) to ensure all of the platform specific SimpleIoc calls are made in ViewModelLocator.

I've added public default ctors in the classes that are complaining about the error (I have though set the PreferredConstructor to the original, not the newly added public ctor).

I have a feeling that this error is a false positive (something else is failing, but pointing at that code).

Using Xam.iOS via a build server (the code is coming from VS2015). Xcode is running the 8.3 emulators (it may need updating to allow for 8.4 testing)

like image 831
Nodoid Avatar asked Oct 30 '22 21:10

Nodoid


1 Answers

It could be that the Linker is optimising away the constructor, if it thinks it's not used. Try setting the Linker Options to "Don't Link" and see if it does it again, or even new-up an instance of the class elsewhere so that the Linker knows that the constructor is used. You don't necessarily want to leave it that way, but if it eliminates the error, you'll at least know the reason.

like image 165
Steve Morgan Avatar answered Nov 17 '22 13:11

Steve Morgan