Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin solution: exception when I try to use a component in the same project (different namespace)

In my Xamarin solution, I added a new library project in a Controls solution folder. From my XAML in Views I called my component and everything was working fine.

I don't know if something changed today after the update to iOS 10 and Visual Studio for Mac but not if I try to compile my solution, I receive an error

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Xamarin.Forms.Xaml.XamlParseException: Position 43:38. Type Doughnut not found in xmlns clr-namespace:Mobile.Controls.Wheel;assembly=Mobile.Controls.Wheel
at Xamarin.Forms.Xaml.Internals.XamlTypeResolver.Xamarin.Forms.Xaml.IXamlTypeResolver.Resolve (System.String qualifiedTypeName, System.IServiceProvider serviceProvider)

The XAML page is so defined:

<ContentPage [...]
    xmlns:ctl="clr-namespace:Mobile.Controls.Wheel;assembly=Mobile.Controls.Wheel" 
    x:Class="Views.DashboardPage">
    <StackLayout>
        <ctl:Doughnut HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" />
    </StackLayout>
</ContentPage>

Doughnut is a class derived from ContentView in Mobile.Controls.Wheel.

like image 813
Enrico Rossini Avatar asked Sep 20 '17 16:09

Enrico Rossini


1 Answers

I have faced the same issue with iOS earlier,

Adding empty class in PCL wth empty static init() method and calling it on iOS’s AppDelegate method solves this Issue when either “Dont’t Link” or “Link SDK assemblies only” is selected in “Linker Options” of iOS Build options.

In your Doughnut class, add a Empty Do-Nothing static Init Method and call this method from iOS's AppDelegate:

In Doughnut.cs add the below method

//Do Nothing Init Method:
public static void Init(){

}

In AppDelegate.cs, add the below line before calling LoadApplication method

Mobile.Controls.Wheel.Doughnut.Init();

Hope this solves your issue, if any information needed let me know.

like image 115
Dinash Avatar answered Oct 28 '22 00:10

Dinash