I am making a Xamarin Forms app, the solution is called RESTTest
, my shared project is called RestApp
.
In my shared project I have a folder called ViewModels
, which contains a class called MainViewModel.cs
I have a page called MainPage.xaml
which has a code-behind called MainPage.xaml.cs
. In my XAML I am trying to include my Viewmodels folder like this:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:RestApp"
x:Class="RestApp.MainPage"
xmlns:ViewModels="clr-namespace:RestApp.ViewModels;assembly=RestApp">
But when I add binding to my page like this:
<ContentPage.BindingContext>
<ViewModels:MainViewModel />
</ContentPage.BindingContext>
I am getting an unhandled exception:
Type ViewModels:MainViewModel not found in xmlns clr-namespace:RestApp.ViewModels;assembly=RestApp
What am I missing?
Removing the ";assembly=RestApp" in the namespace, and setting the linker behaviour to "Link SDK Assemblies Only" worked for me and solved the problem!
This usually happens when you have Linker optimizations that trim unused code.
Note that deserialization into a type may not be detectable by the linker as a type use.
In the properties of your project find the "Linker Behavior" option under "iOS Build" or "Android Build", and set it to either "Link SDK assemblies only" or "Don’t Link". You'll need to clean+rebuild your whole solution for the change to take effect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With