I've got a Standard Library project in a Xamarin solution that produces XAML views. It references XAML controls that I built in a separate library. It crashes at runtime with:
Exception thrown: 'Xamarin.Forms.Xaml.XamlParseException' in Xamarin.Forms.Xaml.dll
Position 35:34. Type trcontrols:EmbeddedImageSource not found in xmlns clr-namespace:ThetaRex.Forms.Controls;assembly=ThetaRex.Forms
The designer has no problem finding this reference and will even complain when it isn't there. If I place a reference to the shared library in the initialization routine for the view, it works:
public FolderView(FolderViewModel folderViewModel) { // Initialize the IDE maintained components. this.InitializeComponent(); // Required to access this object in XAML. EmbeddedImageSource embeddedImageSource = new EmbeddedImageSource(); // Provide a view model for the page. this.BindingContext = this.ViewModel = folderViewModel; }
But if I remove the line with the EmbeddedImageSource on it, I get the error again. I've found other posts which suggest that the assembly is optimized out of the referenced libraries if there's only XAML reference.
Anyone have a clue how to 1.) Report this? 2.) Work around it?
Answers
Try to declarate only the namespace like:
Similar issue:
https://forums.xamarin.com/discussion/126081/xamarin-forms-xaml-xamlparseexception-has-been-thrown
https://forums.xamarin.com/discussion/comment/320818/#Comment_320818