Xamarin Forms InitalizeComponent call does not initialize page controls

731 Views Asked by At

I have a pretty straightforward page that has a few controls on it. My problem only occurs on an actual device and only occurs on my Lumia 1520 running Win10 Mobile version 1607 Build 10.0.14946.1000. It does not happen on my Lumia 950 running Win10 Mobile version 1607 OS Build 10.0.14393.693.

On the 1520 I un-install my app, reboot the device and then attempt to debug the app on the device. Everything works fine. I then stop debugging and attempt to start debugging again and the InitializeComponent method of my page does not initialized any of my controls.

What that means is that after this code runs:

    [System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Forms.Build.Tasks.XamlG", "0.0.0.0")]
    private void InitializeComponent() {
        this.LoadFromXaml(typeof(nearbyplaces));
        pgHeader = this.FindByName<global::GBarScene.pageheader>("pgHeader");
        lblPlacesTitle = this.FindByName<global::Xamarin.Forms.Label>("lblPlacesTitle");
        btnMapAll = this.FindByName<global::Xamarin.Forms.Label>("btnMapAll");
        lblDataSource  = this.FindByName<global::Xamarin.Forms.Label>("lblDataSource ");
        btnUseGPS = this.FindByName<global::Xamarin.Forms.Image>("btnUseGPS");
        lblRatingsFor = this.FindByName<global::Xamarin.Forms.Label>("lblRatingsFor");
        lblDowName = this.FindByName<global::Xamarin.Forms.Label>("lblDowName");
        bvUnderline = this.FindByName<global::Xamarin.Forms.BoxView>("bvUnderline");
        lvPlaces = this.FindByName<global::Xamarin.Forms.ListView>("lvPlaces");
    }

Every control (psHeader, lvPlaces etc.) are all still null. (If I attempt to launch the app on the 1520 without debugging after running it the first time, it crashes)

I see nothing in the output window indicates there was a challenge in other areas. Any idea why this is happening?

UPDATE UPDATE: So I reset the device (I got the same build etc) and tried testing again. I am now getting some error information. Below are the steps to reproduce the error as well as the error information:

  1. Un-install any previous version of the app from the Device.
  2. Restart the device
  3. Test the app on the device. (It should work fine.)
  4. Click the Stop button in the Visual Studio 2015 environment
  5. At this point simply click the Run button in Visual Studio without making changes in the App, it will launch fine on the phone.
  6. Click the Stop button in the Visual Studio 2015 environment
  7. Make a change in the main page of the application and recompile. Ensure the Build line shows at least 1 project succeeded and not just all up to date or skipped.

    2 succeeded, 0 failed, 0 up-to-date, 2 skipped ==========

    1. Run the application on the Device again.

An error is generated at the LoadApplication line shown below:

public sealed partial class MainPage
{
    public MainPage()
    {
        this.InitializeComponent();

        this.NavigationCacheMode = NavigationCacheMode.Required;

        LoadApplication(new GBarScene.App());

Below is the error information: An exception of type 'System.ArgumentNullException' occurred in Xamarin.Forms.Platform.WinRT.ni.DLL but was not handled in user code.

I click on the View Details and I see the following information: "Value cannot be null.\r\nParameter name: newRoot"}

I hope this helps in getting this problem resolved.

UPDATE: The problem also happens on my Lumia 640 XL that was upgraded to Win 10 Mobile.

0

There are 0 best solutions below