Debhere
Debhere

Reputation: 1075

In XAMARIN Unhandled Exception in XAML control which is difficult to debug

Let me first tell you that this is not a very specific question I want to ask but its a general topic I want to discuss about Xamarin.

I have started to work with Xamarin recently and after initial struggle to set up the Visual studio 2015 and android sdk etc. Now I am facing a different kind of issues in code. Specially in XAML.

First of all there is no designer in Xamarin-XAML like WPF-XAML and "XAML.Forms Previewer" doesn't work like WPF XAML. But I can understand this limitations and anybody worked with WPF can easily figure out the Controls and layout with little difficulty.

However what problem I am facing is, there is huge gap between a control and its associated attributes. For example If I put a control Label and if I hit the intellisense it shows all the available controls and its attributes too. It doesn't filter the Label specific attributes. So its difficult to know which attributes this Xamarin Label accepts. (Only options is through Xamarin.Docs). But if I accidentally assign some attributes that doesn't support by the Label then It doesn't show any error during build or Compile time. Only at the deployment time I get "UnHandled Exception". Which sometimes very difficult to debug.

Anybody facing this kind of situation and knows how to resolve this generic "Unhandled exception" could please share the experiences.

Edit 2:

After adding the XAMLC options enter image description here

Upvotes: 0

Views: 1480

Answers (1)

SushiHangover
SushiHangover

Reputation: 74094

XAMLC

Add the XamlCompilation assembly-level attribute to compile your XAML and it will help in catching a majority of those runtime exceptions:

[assembly: XamlCompilation (XamlCompilationOptions.Compile)]

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.

https://developer.xamarin.com/guides/xamarin-forms/xaml/xamlc/

XAML Previewer for Xamarin.Forms

The previewer is available for Visual Studio, Xamarin Studio and Visual Studio for Mac

enter image description here https://developer.xamarin.com/guides/xamarin-forms/xaml/xaml-previewer/

Upvotes: 1

Related Questions