Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring XmlReader{Async} to one behavior #51736

Merged
merged 5 commits into from
Sep 20, 2021
Merged

Conversation

kronic
Copy link
Contributor

@kronic kronic commented Apr 23, 2021

@ghost
Copy link

ghost commented Apr 23, 2021

Tagging subscribers to this area: @buyaa-n, @krwq
See info in area-owners.md if you want to be subscribed.

Issue Details

see XmlRederAsync.ReadElementContentAsAsync
XmlRederAsync.ReadContentAsAsync

Author: kronic
Assignees: -
Labels:

area-System.Xml

Milestone: -

@krwq
Copy link
Member

krwq commented Apr 27, 2021

@kronic are there any functional differences between those two calls? If yes please update the issue with all info, if not please update the issue we can easily tell the code is the same. This is needed for reference in case we get a regression or if this is intentional break we can understand why this change happened (make sure links use specific commit and not main branch which can make them out of date).

@kronic
Copy link
Contributor Author

kronic commented May 8, 2021

@krwq Yes, there are differences in return types XmlAtomicValue, XPathItem, XmlAtomicValue[], XPathItem[], XPathNavigator[]

@krwq
Copy link
Member

krwq commented May 8, 2021

@kronic can you give more specific examples of differences? i.e. input and API output

@kronic
Copy link
Contributor Author

kronic commented May 12, 2021

@krwq In the first case there will be a mistake, in the second there is no

using System;
using System.IO;
using System.Xml;
using System.Xml.Schema;

const string xml = "<test a=\"sdf\"/>";
//1
try
{
	using var xmlReader = XmlReader.Create(new StringReader(xml));
	xmlReader.MoveToContent();
	xmlReader.MoveToAttribute(0);

	if (xmlReader.ReadContentAs(typeof(XmlAtomicValue), null) is XmlAtomicValue xmlAtomic)
	{
//{"Content cannot be converted to the type System.Xml.Schema.XmlAtomicValue. Line 1, position 7."}
		Console.WriteLine(xmlAtomic.Value);
	}
}
catch (Exception ex)
{
	Console.WriteLine(ex);
}
//2
try
{
	using var xmlReader = XmlReader.Create(new StringReader(xml), new XmlReaderSettings {Async = true});
	await xmlReader.MoveToContentAsync();
	xmlReader.MoveToAttribute(0);

	if (await xmlReader.ReadContentAsAsync(typeof(XmlAtomicValue), null) is XmlAtomicValue xmlAtomic)
	{
//ok
		Console.WriteLine(xmlAtomic.Value);
	}
}
catch (Exception ex)
{
	Console.WriteLine(ex);
}

@kronic
Copy link
Contributor Author

kronic commented May 12, 2021

#52646

@kronic
Copy link
Contributor Author

kronic commented May 27, 2021

@krwq ping

@@ -534,7 +534,7 @@ public virtual object ReadElementContentAs(Type returnType, IXmlNamespaceResolve
return value;
}

return returnType == typeof(string) ? string.Empty : XmlUntypedStringConverter.Instance.FromString(string.Empty, returnType, namespaceResolver);
return returnType == typeof(string) ? string.Empty : XmlUntypedConverter.Untyped.ChangeType(string.Empty, returnType, namespaceResolver);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the new implementation will not work with list types correctly. I think the correct solution might be just changing Untyped into UntypedList but you will need to add tests which cover this.

Copy link
Contributor Author

@kronic kronic Aug 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XmlRederAsync use Untyped

return XmlUntypedConverter.Untyped.ChangeType(strContentValue, returnType, namespaceResolver ?? this as IXmlNamespaceResolver);

@krwq
Copy link
Member

krwq commented Jun 7, 2021

@kronic sorry for late re-review. You will need to add more tests related to list types as I think there are some differences in the implementation (by default XmlUntypedStringConverter.Instance handles lists while XmlUntypedConverter.Untyped doesn't). I think the solution is to change to XmlUntypedConverter.UntypedList but you will need to add tests to confirm everything works. Make sure to analyze both implementations and ensure there are no differences in behavior.

@terrajobst terrajobst added the community-contribution Indicates that the PR has been added by a community member label Jul 19, 2021
@jeffhandley
Copy link
Member

@kronic I'm sorry we had a long delay on reviewing this. We will be ready to re-review if you want to address the feedback @krwq left.

Assigning to @krwq to track and follow-up as needed.

@krwq krwq added this to the 7.0.0 milestone Aug 12, 2021
@krwq krwq added the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Aug 12, 2021
@krwq
Copy link
Member

krwq commented Aug 12, 2021

no merge until RC1 snap

@kronic
Copy link
Contributor Author

kronic commented Aug 17, 2021

@krwq done

@krwq krwq removed the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Aug 19, 2021
Assert.Equal(4, values.Length);
Assert.Equal(1, values[0]);
Assert.Equal(2, values[1]);
Assert.Equal(3, values[2]);
Assert.Equal(4, values[3]);
}
[Fact]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: new line between } and [Fact] - here and everywhere

@krwq
Copy link
Member

krwq commented Sep 16, 2021

/azp list

@krwq
Copy link
Member

krwq commented Sep 16, 2021

/azp run runtime-libraries-coreclr outerloop

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@krwq
Copy link
Member

krwq commented Sep 16, 2021

LGTM assuming no related failures in outerloop tests - we should watch closely for any potential regressions caused by this PR since there might be some obscure cases which we might hit

@krwq krwq merged commit 6c9921d into dotnet:main Sep 20, 2021
@kronic kronic deleted the Remove_dead_code branch September 20, 2021 09:29
@ghost ghost locked as resolved and limited conversation to collaborators Nov 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Xml community-contribution Indicates that the PR has been added by a community member
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

XmlReader.ReadContentAs{Async} different behavior
4 participants