Enrico
Enrico

Reputation: 6214

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.

Upvotes: 7

Views: 158

Answers (1)

Dinash
Dinash

Reputation: 3047

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.

Upvotes: 2

Related Questions