Bug 17818 - ReadElementContentAs and DateTimeOffset
Summary: ReadElementContentAs and DateTimeOffset
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.XML ()
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: marcos.henrich
URL:
Depends on:
Blocks:
 
Reported: 2014-02-17 11:31 UTC by Marek Safar
Modified: 2014-08-28 12:09 UTC (History)
2 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 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:
Status:
RESOLVED FIXED

Description Marek Safar 2014-02-17 11:31:45 UTC
using System;
using System.Collections.Generic;
using System.Xml;
using System.IO;

class X
{
	public static void Main ()
	{
		string xml1 = "<root><![CDATA[9]]>999Z</root>";
		var xr = XmlReader.Create (new StringReader (xml1));
		xr.Read ();

		var x = xr.ReadElementContentAs (typeof(DateTimeOffset), null);
		Console.WriteLine (x);
		return;
	}
}

Mono throws

System.Xml.XmlException: Current text value '9999Z' is not acceptable for specified type 'System.DateTimeOffset'. Invalid format string  Line 1, position 26.
  at System.Xml.XmlReader.ValueAs (System.String text, System.Type type, IXmlNamespaceResolver resolver, Boolean isArrayItem) [0x00000] in <filename unknown>:0
  at System.Xml.XmlReader.ReadElementContentAs (System.Type returnType, IXmlNamespaceResolver namespaceResolver) [0x00000] in <filename unknown>:0
  at X.Main () [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.Xml.XmlException: Current text value '9999Z' is not acceptable for specified type 'System.DateTimeOffset'. Invalid format string  Line 1, position 26.
  at System.Xml.XmlReader.ValueAs (System.String text, System.Type type, IXmlNamespaceResolver resolver, Boolean isArrayItem) [0x00000] in <filename unknown>:0
  at System.Xml.XmlReader.ReadElementContentAs (System.Type returnType, IXmlNamespaceResolver namespaceResolver) [0x00000] in <filename unknown>:0
  at X.Main () [0x00000] in <filename unknown>:0

.NET

1/1/9999 12:00:00 AM +00:00
Comment 1 marcos.henrich 2014-08-28 11:58:38 UTC
Hi Marek,

Thank you for the detailed bug report.

The pull request for this issue can be found in the link below.
https://github.com/mono/mono/pull/1234
Comment 2 marcos.henrich 2014-08-28 12:09:40 UTC
Fixed in master 33c345a945fb67d8964213dc032214ba65e55321
https://github.com/mono/mono/commit/33c345a945fb67d8964213dc032214ba65e55321