Bug 56433 - Non-Descript XAML Parsing Exception
Summary: Non-Descript XAML Parsing Exception
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Stephane Delcroix
URL:
Depends on:
Blocks:
 
Reported: 2017-05-15 03:20 UTC by Melbourne Developer
Modified: 2018-01-25 10:02 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED NOT_REPRODUCIBLE

Description Melbourne Developer 2017-05-15 03:20:19 UTC
If you do not provide a default namespace in XAML, the XAML parser will throw a non-descript exception. The message will be:

System.ArgumentNullException: Value cannot be null.

The code can be found here:
https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Core/XmlnsDefinitionAttribute.cs

It happens here:
			if (clrNamespace == null)
throw new ArgumentNullException(nameof(clrNamespace));


The exception that is thrown is here should either be less generic and handled at a higher level, or the message of the exception should be more descriptive and should include a clear reason as to why the exception is being thrown.

Here are a few forum posts on the topic:

http://stackoverflow.com/questions/42638197/generated-code-behind-throws-system-argumentnullexception
https://forums.xamarin.com/discussion/95441/xmlnsdefinitionattribute-argumentnullexception-parameter-name-clrnamespace/p1?new=1
Comment 1 Stephane Delcroix 2017-05-15 20:41:03 UTC
If the default xmlns is missing, the partial class won't be generated (XamlG) and the assembly won't compile, so you're not supposed to run the project, and get a runtime issue.

To get this, you're invoking an internal API, and the observed behavior is not a bug.
Comment 2 Melbourne Developer 2018-01-14 04:40:47 UTC
I got this error again today, so I googled for it, and saw my post here:

https://forums.xamarin.com/discussion/95441/xmlnsdefinitionattribute-argumentnullexception-parameter-name-clrnamespace

Which led my back to this bug. It's still a bug that needs to be fixed. The bug is that the error message needs to more descriptive. I don't know if this is a bug in Xamarin Forms, or a bug in Visual Studio, but regardless, the error message should say something like:

Default xmlns is missing. The partial class won't be generated for XAML file [INSERT FILENAME HERE].
Comment 3 Melbourne Developer 2018-01-14 04:45:59 UTC
It's not actually the default xmlns thought - it's the default namespace of the project.
Comment 4 Melbourne Developer 2018-01-14 05:01:27 UTC
I'm now getting this in the latest version of Xamarin Forms. 2.5.0.122203

And, I DO have a default namespace at the project. And, this is now control is defined in XAML:

<?xml version="1.0" encoding="UTF-8"?>
<Grid   
    xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="Portfolio"
    x:Class="Wallet.Pages.CoinCard">

</Grid>
Comment 5 Melbourne Developer 2018-01-14 05:02:19 UTC
When I remove the XamlCompilation attribute, it compiles fine.
Comment 6 Melbourne Developer 2018-01-14 05:04:45 UTC
But, when I do remove the attribute, I get nothing on the screen. It's just blank.
Comment 7 Stephane Delcroix 2018-01-15 08:55:08 UTC
I don't understand what's wrong in #c4. Please add a small retro-project.
thanks
Comment 8 Jules 2018-01-21 15:47:13 UTC
I'm starting to have this error now too. The clrNamespace param is also null, but it is declared in the XAML file
Comment 9 Melbourne Developer 2018-01-21 23:48:30 UTC
I can't recreate it. It just happens sometimes and then stops happening.
Comment 10 Stephane Delcroix 2018-01-22 09:14:02 UTC
closing as not reproducible.

if you can provide a reproduction project, please open an issue on https://github.com/xamarin/Xamarin.Forms/issues