Bug 23782 - Error executing task XamlG: Text node cannot appear in this state
Summary: Error executing task XamlG: Text node cannot appear in this state
Status: RESOLVED NORESPONSE
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: unspecified
Hardware: Macintosh Mac OS
: High normal
Target Milestone: ---
Assignee: Stephane Delcroix
URL:
Depends on:
Blocks:
 
Reported: 2014-10-13 12:47 UTC by Dan Vanderboom
Modified: 2016-03-18 08:32 UTC (History)
12 users (show)

Tags: ngf
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 NORESPONSE

Description Dan Vanderboom 2014-10-13 12:47:54 UTC
Description of Problem:
After building an app for four months on Xamarin.Forms, my Xamarin.Forms PCL library no longer builds. I get errors that the XamlG build task is failing. It usually complains about line 1, column 1 of Xamarin.Forms.targets. If I change anything in one of the XAML files, then I get an additional error message complaining about the newly-edited file, for as many XAML files as I edit.

Steps to reproduce the problem:
1. From outside of my project file? Not sure. I started with a new PCL project, included Xamarin.Forms package, and started adding my 15 XAML/XAML.cs files to this new project. There are dependencies, so it will be quite hard to add them one at a time to see which one may be causing the problem.

Actual Results:
Reported in detail here (diagnostic build output): 
http://forums.xamarin.com/discussion/25848/error-executing-task-xamlg-text-node-cannot-appear-in-this-state-no-other-errors-reported#latest

The key bit of info seems to be: Xamarin.Forms.targets: error : Error executing task XamlG: Text node cannot appear in this state. Line 1, position 1. Error executing task XamlG: System.Xml.XmlException: Text node cannot appear in this state. Line 1, position 1. at Mono.Xml2.XmlTextReader.ReadText (Boolean notWhitespace)

Expected Results:
Successful build!

How often does this happen? 
Every single time I try to build that project. This is a complete show-stopper for the project I'm working on until it's resolved.

Additional Information:
I've tried reverting to old versions of Xamarin Studio (on Mac), older versions of Xamarin.Forms, and I've restarted Xamarin Studio and my Mac of course.

The only thing that seemed to get it to build again is to revert to an older version of my code. I read somewhere that XAML files could become corrupt, especially if updating nuget packages on a Windows computer and then coming back to use them on Mac. When I tried rebuilding the project from scratch, I created brand new XAML files and pasted the content into them.

Could I have copied some invalid, invisible characters via copy & paste into a new file? I'm not sure.
Comment 1 Dan Vanderboom 2014-10-13 12:48:51 UTC
Even if I am doing something wrong/stupid in XAML--and I've been looking, but haven't found anything yet--I should still get a better error message, if indeed it is something I've done.
Comment 2 Ram Chandra 2014-10-14 07:09:23 UTC
I have checked this issue and I am able to reproduce this issue.

Steps I followed:

1. Create a Blank App ( Xamarin.Forms Portable)
2. Add new Forms ContentPage Xaml page.
3. Write any character at the very beginning of XAML file.
4. Build the solution.

When I add any character at the very beginning of XAML file observed that I am getting following error:
"Error: Unknown MSBuild failure. Please try building the project again".

When I check the Tool output I observed that tool output contains following error:
"error : Error executing task XamlG: Text node cannot appear in this state."

Screencast:  http://www.screencast.com/t/2nrmeyVVLHbj

Build output: https://gist.github.com/saurabh360/27169614a180591b369a
Tool output:  https://gist.github.com/saurabh360/27169614a180591b369a

Environment Info:

Xamarin.Forms: 1.2.3.6257

=== Xamarin Studio ===

Version 5.6.1 (build 5)
Installation UUID: 6ea47b0d-1852-4aaf-808d-373ff0a5002b
Runtime:
    Mono 3.10.0 ((detached/633e444)
    GTK+ 2.24.23 (Raleigh theme)

    Package version: 310000020

=== Apple Developer Tools ===

Xcode 6.0.1 (6528)
Build 6A317

=== Xamarin.Mac ===

Version: 1.10.0.18 (Business Edition)

=== Xamarin.Android ===

Version: 4.18.0 (Business Edition)
Android SDK: /Users/jatin66/Desktop/Backup/android-sdk-macosx
    Supported Android versions:
        1.6   (API level 4)
        2.1   (API level 7)
        2.2   (API level 8)
        2.3   (API level 10)
        3.0   (API level 11)
        3.1   (API level 12)
        3.2   (API level 13)
        4.0   (API level 14)
        4.0.3 (API level 15)
        4.1   (API level 16)
        4.2   (API level 17)
        4.3   (API level 18)
        4.4   (API level 19)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Xamarin.iOS ===

Version: 8.2.0.203 (Business Edition)
Hash: 6049af6
Branch: 
Build date: 2014-10-12 21:49:14-0400

=== Build Information ===

Release ID: 506010005
Git revision: 4a603dc77610b9eff2a41582146c56b69a81ceba
Build date: 2014-10-09 11:07:06-04

=== Operating System ===

Mac OS X 10.9.5
Comment 3 winnicki.derek 2014-10-31 00:01:13 UTC
+1
I'm getting the same behavior. I've been working on a Xamarin.Forms PCL project for some time now but haven't been using XAML. Today refactored a ContentPage to use XAML with code behind. I added the InitializeComponent statement to the code behind, and changed the BuildAction to EmbeddedResource with Custom Tool set to MSBuild:Compile. Now when I build I'm getting Unknown MSBuild failure (even from a few XAML's in referenced projects that I haven't touched).

Xamarin Studio
Version 5.6.2 (build 5)
Installation UUID: 4ac8e248-cce8-42a6-b3d2-cafcaac13200
Runtime:
	Mono 3.10.0 ((detached/633e444)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 310000020

Apple Developer Tools
Xcode 6.0.1 (6528)
Build 6A317

Xamarin.iOS
Version: 8.4.0.15 (Indie Edition)
Hash: 08968c4
Branch: 
Build date: 2014-10-20 21:48:06-0400

Xamarin.Android
Version: 4.18.0 (Indie Edition)
Android SDK: /Users/winnicki/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		4.0   (API level 14)
		4.0.3 (API level 15)
		4.4   (API level 19)
Java SDK: /usr
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

Xamarin.Mac
Version:

Build Information
Release ID: 506020005
Git revision: 19bc3b64b70332bfab18faf9cf1ce7d3aa191b36
Build date: 2014-10-17 14:49:01-04

Operating System
Mac OS X 10.9.5
Comment 4 winnicki.derek 2014-10-31 00:28:28 UTC
I reverted to the previous version to get the project to build again. I then add a new XAML ContentPage with code behind to the project and without touching it I now receive "/FeedPage.xaml: Error: The 'MSBuild:Compile' code generator crashed: Collection was modified; enumeration operation may not execute. "

A second time I reverted in order to build again and this time I added my XAML with code-behind that I want to actually use and I receive the Unkown Build Error message. As soon as I get this error, 3 other XAML files in separate projects that haven't been touched also display the error.

Hope this helps somehow.. I was looking forward to writing all my views in XAML but looks like I'll have to wait.
Comment 5 Greg Munn 2014-12-04 10:37:08 UTC
We've been looking into this and, without access to the actual files that are exhibiting this error, we think that it might be because of an Encoding issue.

We can reproduce the error by changing the encoding

for example
> iconv -f utf-8 -t utf-16 MyPage.orig.xaml > MyPage.xaml

changing the encoding from utf-8 to utf16 reproduces the error.

> file -I MyPage.xaml
MyPage.xaml: application/xml; charset=utf-16be

To workaround this you can either 
  1. use Save As to save the file as UTF-8 again (Xamarin Studio will default to this encoding so don't rely on the save dialog to tell you what encoding the file currently is)

  2. use a different editor to do the same thing, I tested this with TextWrangler

  3. Edit the first line, or remove it entirely. (*)



* After reproducing the issue using iconv, I noticed when I edited the file in TextWrangler that there was a single space before the <?xml on the first line. Xamarin Studio for some reason did not show that character. Editing the line in Xamarin Studio fixed up the file so that, even though the encoding was utf-16 it was able to build the application.

The issue remains though, what happened to the xaml files in the first place and is this a valid reproduction of the issue. I would very much appreciate it if, when this happens again, if you could attach the .xaml file to the bug and report back with the encoding. 


Similar thread on SO http://stackoverflow.com/questions/8625705/xmlexception-text-node-cannot-appear-in-this-state. seems to indicate that the encoding changed.
Comment 6 Adam Kemp 2014-12-04 11:31:57 UTC
It sounds like you're describing a Byte Order Mark. I think the parser should handle that.
Comment 7 Greg Munn 2014-12-04 12:35:57 UTC
My reproduction of the issue is really quite contrived. Looking at the file in hexdump it shows 2 BOM's, which probably causes the error.

What I need to further this bug along is an actual instance of the problem, so if this happens again, please attach the xaml file to this report so we can investigate further.

Cheers.
Comment 8 PJ 2014-12-04 14:00:05 UTC
Not sure we'll be able to reliably fix this for 5.7, moving off milestone.
Comment 11 Jason Smith [MSFT] 2016-03-18 08:32:45 UTC
Thank you for taking the time to submit this report. After reviewing the description of this bug, we no longer believe it affects the current version of Xamarin.Forms. If you are still experiencing the issue after updating your packages, please reopen this report with an attached reproduction.
 
For your convenience, we have created some reproduction best practices viewable here: https://gist.github.com/jassmith/92405c300e54a01dcc6d

Warm regards,
Xamarin Forms Team