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

SqlCommand.ExecuteXmlReaderAsync() returns an XmlReader object with Settings.Async = false #781

Closed
GMacAussie opened this issue Nov 3, 2020 · 3 comments · Fixed by #782
Labels
🐛 Bug! Something isn't right !

Comments

@GMacAussie
Copy link

Describe the bug

The SqlCommand ExecuteXmlReaderAsync() method returns an XmlReader object. However, methods (such as MoveToContentAsync) against this XmlReader object raise:

  • A 'Set XmlReaderSettings.Async to true if you want to use Async Methods.' exception for Microsoft.Data.SqlClient
  • A 'Specified method is not supported.' exception for System.Data.SqlClient.

Examining the XmlReader object, the Settings.Async flag is false which means that the Async methods cannot be used against it.

It appears that the XmlReader object was created by the ExecuteXmlReaderAsync() method with the Async setting as false (or default). This flag is read-only so this method must itself set the flag true.

Microsoft.Data.SqlClient 2.1.0-preview2.20297.7

Exception message: Set XmlReaderSettings.Async to true if you want to use Async Methods.
Stack trace:
Async Read Exception: System.InvalidOperationException: Set XmlReaderSettings.Async to true if you want to use Async Methods.
   at System.Xml.XmlTextReaderImpl.CheckAsyncCall()
   at System.Xml.XmlTextReaderImpl.ReadAsync()
   at System.Xml.XmlReader.<MoveToContentAsync>d__197.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at AsyncXmlReader.MicrosoftAsyncXmlReader.<AsyncRead>d__2.MoveNext() in C:\src\3rdparty\AsyncXmlReader\AsyncXmlReader\MicrosoftAsyncXmlReader.cs:line 58

System.Data.SqlClient 4.7.2

Exception message: Specified method is not supported.
Stack trace:
Async Read Exception: System.NotSupportedException: Specified method is not supported.
   at System.Xml.XmlSqlBinaryReader.MoveToContentAsync()
   at AsyncXmlReader.SystemAsyncXmlReader.<AsyncRead>d__2.MoveNext() in C:\src\3rdparty\AsyncXmlReader\AsyncXmlReader\SystemAsyncXmlReader.cs:line 57

To reproduce

See attached solution that attempts to use ExecuteXmlReaderAsync() method against Microsoft.Data.SqlClient and System.Data.SqlClient libraries.

AsyncXmlReader.zip

Expected behavior

SqlCommand ExecuteXmlReaderAsync() method should return an XmlReader object that has XmlReaderSettings.Async set to true so that further Async methods against the XmlReader object work as expected.

Further technical details

Microsoft.Data.SqlClient version: 2.1.0-preview2.20297.7
.NET target: 4.7.2
SQL Server version: SQL Server 14.0.1000
Operating system: Windows 10 Pro Version 10.0.19041 Build 19041

Additional context
This was reported for System.Data.SqlClient but I was directed here and reproduced it for Microsoft.Data.SqlClient:
https://developercommunity2.visualstudio.com/t/sqlcommandexecutexmlreaderasync-returns-an-xmlread/926539

cheenamalhotra added a commit to cheenamalhotra/SqlClient that referenced this issue Nov 3, 2020
cheenamalhotra added a commit to cheenamalhotra/SqlClient that referenced this issue Nov 3, 2020
@cheenamalhotra
Copy link
Member

Hi @GMacAussie

Thanks for bringing this to our attention. I've created PR #782 to fix this issue.
It seems like this issue existed from long ago (reproduced also in System.Data.SqlClient (.NET Framework 4.6.1)), this fix will be applicable to Microsoft.Data.SqlClient future versions.

@cheenamalhotra cheenamalhotra added this to To do in SqlClient v2.1 via automation Nov 3, 2020
@cheenamalhotra cheenamalhotra added the 🐛 Bug! Something isn't right ! label Nov 3, 2020
@cheenamalhotra cheenamalhotra moved this from To do to Review in progress in SqlClient v2.1 Nov 3, 2020
cheenamalhotra added a commit to cheenamalhotra/SqlClient that referenced this issue Nov 3, 2020
@cheenamalhotra cheenamalhotra removed this from Review in progress in SqlClient v2.1 Nov 5, 2020
@cheenamalhotra cheenamalhotra added this to To do in SqlClient v2.1 via automation Nov 5, 2020
@cheenamalhotra cheenamalhotra moved this from To do to Review in progress in SqlClient v2.1 Nov 5, 2020
SqlClient v2.1 automation moved this from Review in progress to Done Nov 10, 2020
@taspeotis
Copy link

The documentation for Microsoft...ExecuteXmlReaderAsync has not been updated?

ExecuteXmlReaderAsync()

...
The XmlReader returned by this method does not support asynchronous operations.

@amw786
Copy link

amw786 commented Apr 2, 2022

Is this issue fixed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug! Something isn't right !
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

4 participants