Reputation: 1121
I'm using xamarin forms, and it's been working fine but suddenly my app is crashing on startup with the error: System.TypeInizilationException has been thrown, and it show my App.Xaml.cs class:
using Xamarin.Forms;
namespace MyApp
{
public partial class App : Application
{
public App()
{
InitializeComponent();
MainPage = new NavigationPage(new AppPage());
}
protected override void OnStart()
{
// Handle when your app starts
}
protected override void OnSleep()
{
// Handle when your app sleeps
}
protected override void OnResume()
{
// Handle when your app resumes
}
}
}
It highlights the line MainPage = new NavigationPage(new AppPage());
as the source of the issue, what would be causing the problem and how do I fix it?
Here is the code of the AppPage class:
using Xamarin.Forms;
using Microsoft.WindowsAzure.MobileServices;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyApp
{
public partial class AppPage : ContentPage
{
public AppPage()
{
InitializeComponent();
}
protected override async void OnAppearing()
{
base.OnAppearing();
//Code
}
}
}
App.Xaml class:
<?xml version="1.0" encoding="utf-8"?>
<Application xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="MyApp.app">
<Application.Resources>
<!-- Application resource dictionary -->
</Application.Resources>
</Application>
Inner Exception:
System.PlatformNotSupportedException: The empty PCL implementation for Microsoft Azure Mobile Services was loaded. Ensure you have added nuget package to each of your platform projects.
at Microsoft.WindowsAzure.MobileServices.Platform.get_Instance () [0x00007] in <7910de25d05d49d9b3c2d648cd285e40>:0
at Microsoft.WindowsAzure.MobileServices.MobileServiceClient.GetApplicationInstallationId () [0x00004] in <7910de25d05d49d9b3c2d648cd285e40>:0
at Microsoft.WindowsAzure.MobileServices.MobileServiceClient..ctor (System.Uri mobileAppUri, System.Net.Http.HttpMessageHandler[] handlers) [0x0005f] in <7910de25d05d49d9b3c2d648cd285e40>:0
at Microsoft.WindowsAzure.MobileServices.MobileServiceClient..ctor (System.String mobileAppUri, System.Net.Http.HttpMessageHandler[] handlers) [0x00008] in <7910de25d05d49d9b3c2d648cd285e40>:0
at ChurchBuilder.ChurchBuilderPage..cctor () [0x00000] in /Users/taylordowns/Projects/ChurchBuilder/ChurchBuilder/ChurchBuilderPage.xaml.cs:24
Upvotes: 0
Views: 66
Reputation: 81483
For these types of benign problems and errors with Xamarin
you need to go through a process of elimination and get as much information as you can to diagnose the problem.
1. Rule out the environment
I know this seems pedantic however you would be surprised how often this helps.
2. Get as much error information
As an Example
try
{
InitializeComponent();
MainPage = new NavigationPage(new AppPage());
}
catch (Exception ex)
{ // break point here and inspect ex
}
Look at the exception in detail, look at all inner exceptions and of course look at the stack trace in depth
3. Check your Xaml with the compilation attribute on your pages and main App class.
Attribute
[XamlCompilation(XamlCompilationOptions.Compile)]
From developer.xamarin.com : XAML Compilation
XAML can be optionally compiled directly into intermediate language (IL) with the XAML compiler (XAMLC).
XAMLC offers a number of a benefits:
- It performs compile-time checking of XAML, notifying the user of any errors.
- It removes some of the load and instantiation time for XAML elements.
- It helps to reduce the file size of the final assembly by no longer including .xaml files.
XAMLC is disabled by default to ensure backwards compatibility. It can be enabled at both the assembly and class level by adding the XamlCompilation attribute.
4. Start commenting out Xaml in your offending page and App.Xaml
This is also a no brainer. If a TypeInizilationException
is being thrown on every page, then its probably a style or resource located in your App.Xaml
Start commenting large parts of your App.Xaml
and Pages
out until something starts to work
I know this is extreme but its pretty quick to find the problem or at least isolate it
Read How to create a Minimal, Complete, and Verifiable example
Upvotes: 1