Bug 2564 - XNamespace not matched correctly
Summary: XNamespace not matched correctly
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.XML ()
Version: 2.10.x
Hardware: All All
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2011-12-19 09:35 UTC by DesDesDes
Modified: 2012-01-19 05:23 UTC (History)
3 users (show)

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

nUnit tests which fail under mono (858 bytes, text/plain)
2011-12-19 09:35 UTC, DesDesDes

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 GitHub or Developer Community 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:

Description DesDesDes 2011-12-19 09:35:37 UTC
Created attachment 1067 [details]
nUnit tests which fail under mono

When adding a XNamespace element to an XElement the element is ignored. Example:

var ns = XNamespace.Get(XmlSchema.InstanceNamespace);
var element = new XElement("Demo", new XAttribute(ns + "nil", true), new XAttribute(XNamespace.Xmlns + "xsi", ns));
Assert.AreEqual("<Demo xsi:nil=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" />", element.ToString());

This test succeeds under MS.NET 4 but fails under mono 2.10.6. Mono returns duplicate namespace declaration:
<Demo d1p1:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:d1p1="http://www.w3.org/2001/XMLSchema-instance" />

Also MS.NET 4 has a defferent naming scheme if the namespace is not explicitly declared. Ms uses p1 as a default prefix while mono starts with d1p1.

A test class is included as an attachment. Both test succeed under MS.NET 4, but fail under mono 2.10.6.
Comment 1 Atsushi Eno 2012-01-19 05:23:14 UTC
This is pretty bad for XElement performance, but I made a fix in git master d18e065 anyways. Thanks for the report.