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

SqlClient: Make SqlDataReader.GetFieldValue<XmlReader>() behave like GetXmlReader() #26756

Closed
bricelam opened this issue Jul 10, 2018 · 0 comments
Labels
area-System.Data.SqlClient enhancement Product code improvement that does NOT require public API changes/additions
Milestone

Comments

@bricelam
Copy link
Contributor

Unfortunately, reader.GetFieldValue<XmlReader>(0) throws the following exception instead of coercing/wrapping the value inside of an XmlReader like calling reader.GetXmlReader(0) does.

System.InvalidCastException: Unable to cast object of type `'System.String' to type 'System.Xml.XmlReader'.

var connection = new SqlConnection(@"Data Source=(localdb)\MSSQLLocalDB");
connection.Open();

var command = connection.CreateCommand();
command.CommandText = "SELECT CAST('<data value=''test''/>' AS xml)";

var reader = command.ExecuteReader();
reader.Read();

// Works
var result1 = reader.GetXmlReader(0);

// Throws
var result2 = reader.GetFieldValue<XmlReader>(0);
@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 3.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Data.SqlClient enhancement Product code improvement that does NOT require public API changes/additions
Projects
None yet
Development

No branches or pull requests

3 participants