2
votes

I have been developing my application using Xamarin Forms and MVVMCross libraries and I have encountered an error, which leads to Xamarin.Forms. I thought I will just download source code for Xamarin Forms and debug it. I have cloned git repository, then added these projects to my solution:

  • Xamarin.Forms.Core
  • Xamarin.Forms.Maps
  • Xamarin.Forms.Maps.Android
  • Xamarin.Forms.Platform
  • Xamarin.Forms.Platform.Android
  • Xamarin.Forms.Platform.Android (Forwarders)
  • Xamarin.Forms.Platform.Android.FormsViewGroup
  • Xamarin.Forms.Xaml

I have removed NuGet references for these libraries and replaced references in my projects. Application is building, everything goes okay at this point, but when I deploy it to an emulator, app crashes. Here is stacktrace:

android.runtime.JavaProxyThrowable: System.ArgumentException: element is not of type Xamarin.Forms.View Parameter name: element at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00011] in F:\workspace\Xamarin.Forms\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:139 at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x00022] in F:\workspace\Xamarin.Forms\Xamarin.Forms.Platform.Android\Platform.cs:289 at Xamarin.Forms.Platform.Android.Platform.AddChild (Xamarin.Forms.VisualElement view, System.Boolean layout) [0x0001d] in F:\workspace\Xamarin.Forms\Xamarin.Forms.Platform.Android\Platform.cs:530 at Xamarin.Forms.Platform.Android.Platform.SetPage (Xamarin.Forms.Page newRoot) [0x000a2] in F:\workspace\Xamarin.Forms\Xamarin.Forms.Platform.Android\Platform.cs:414 at Xamarin.Forms.Platform.Android.FormsApplicationActivity.Inte at md59d637456c2e899bd4a90a05345a07db3.MvxFormsApplicationActivity.n_onCreate(Native Method) at md59d637456c2e899bd4a90a05345a07db3.MvxFormsApplicationActivity.onCreate(MvxFormsApplicationActivity.java:31) at android.app.Activity.performCreate(Activity.java:5231) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) at android.app.ActivityThread.access$800(ActivityThread.java:135) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5001) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) at dalvik.system.NativeStart.main(Native Method)

It looks, like Xamarin cannot find view rednerer for NavigationPage class. I am compiling with Xamarin.Android 7.0 and Java 8.

1
Please include the respective branch/tag of Xamarin.Forms code you pulled down. - Jon Douglas
@JonDouglas I have pulled from 2.3.3 branch - dobowicz
@JonDouglas Right now I have added blank app to Xamarin.Forms solution, replaced all NuGet references with project references of Xamarin.Forms and I get the same error with ContentPage. Is there anything that I should do to make any app working with Xamarin sources? Maybe here is some step, that I am not aware of? - dobowicz
Microsoft instructions at devblogs: Debugging Xamarin Open Source Frameworks: Part 1. - ToolmakerSteve

1 Answers

3
votes

I have finally figured out how to run my app. I have found, that in AssemblyInfo class in Xamarin.Forms.Platform.Android namespace I had grayed out attributes, which were telling application to register renderers for views. This is what I am talking about:

#if ROOT_RENDERERS
[assembly: ExportRenderer (typeof (BoxView), typeof (BoxRenderer))]
[assembly: ExportRenderer (typeof (Entry), typeof (EntryRenderer))]
[assembly: ExportRenderer (typeof (Editor), typeof (EditorRenderer))]
[assembly: ExportRenderer (typeof (Label), typeof (LabelRenderer))]
[assembly: ExportRenderer (typeof (Image), typeof (ImageRenderer))]
[assembly: ExportRenderer (typeof (Button), typeof (ButtonRenderer))]
[assembly: ExportRenderer (typeof (TableView), typeof (TableViewRenderer))]
[assembly: ExportRenderer (typeof (ListView), typeof (ListViewRenderer))]
[assembly: ExportRenderer (typeof (Slider), typeof (SliderRenderer))]
[assembly: ExportRenderer (typeof (WebView), typeof (WebViewRenderer))]
[assembly: ExportRenderer (typeof (SearchBar), typeof (SearchBarRenderer))]
[assembly: ExportRenderer (typeof (Switch), typeof (SwitchRenderer))]
[assembly: ExportRenderer (typeof (DatePicker), typeof (DatePickerRenderer))]
[assembly: ExportRenderer (typeof (TimePicker), typeof (TimePickerRenderer))]
[assembly: ExportRenderer (typeof (Picker), typeof (PickerRenderer))]
[assembly: ExportRenderer (typeof (Stepper), typeof (StepperRenderer))]
[assembly: ExportRenderer (typeof (ProgressBar), typeof (ProgressBarRenderer))]
[assembly: ExportRenderer (typeof (ScrollView), typeof (ScrollViewRenderer))]
[assembly: ExportRenderer (typeof (Toolbar), typeof (ToolbarRenderer))]
[assembly: ExportRenderer (typeof (ActivityIndicator), typeof (ActivityIndicatorRenderer))]
[assembly: ExportRenderer (typeof (Frame), typeof (FrameRenderer))]
[assembly: ExportRenderer (typeof (NavigationMenu), typeof (NavigationMenuRenderer))]
[assembly: ExportRenderer (typeof (OpenGLView), typeof (OpenGLViewRenderer))]

[assembly: ExportRenderer (typeof (TabbedPage), typeof (TabbedRenderer))]
[assembly: ExportRenderer (typeof (NavigationPage), typeof (NavigationRenderer))]
[assembly: ExportRenderer (typeof (CarouselPage), typeof (CarouselPageRenderer))]
[assembly: ExportRenderer (typeof (Page), typeof (PageRenderer))]
[assembly: ExportRenderer (typeof (MasterDetailPage), typeof (MasterDetailRenderer))]
#endif

When I have commented this compilation condition, everything went smooth.