diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextWriter.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextWriter.cs
index c2aa7970b546f..d593a97e7d56e 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextWriter.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextWriter.cs
@@ -760,7 +760,7 @@ public override void WriteComment(string? text)
{
try
{
- if (null != text && (text.Contains("--") || text.StartsWith('-')))
+ if (null != text && (text.Contains("--") || text.EndsWith('-')))
{
throw new ArgumentException(SR.Xml_InvalidCommentChars);
}
diff --git a/src/libraries/System.Private.Xml/tests/XmlWriter/System.Xml.RW.XmlWriter.Tests.csproj b/src/libraries/System.Private.Xml/tests/XmlWriter/System.Xml.RW.XmlWriter.Tests.csproj
index c3e76cb1a3047..3e074e9a835e3 100644
--- a/src/libraries/System.Private.Xml/tests/XmlWriter/System.Xml.RW.XmlWriter.Tests.csproj
+++ b/src/libraries/System.Private.Xml/tests/XmlWriter/System.Xml.RW.XmlWriter.Tests.csproj
@@ -7,5 +7,6 @@
+
\ No newline at end of file
diff --git a/src/libraries/System.Private.Xml/tests/XmlWriter/XmlTextWriterTests.cs b/src/libraries/System.Private.Xml/tests/XmlWriter/XmlTextWriterTests.cs
new file mode 100644
index 0000000000000..5b1063a1fc606
--- /dev/null
+++ b/src/libraries/System.Private.Xml/tests/XmlWriter/XmlTextWriterTests.cs
@@ -0,0 +1,92 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System.Collections.Generic;
+using System.IO;
+using Xunit;
+
+namespace System.Xml.Tests
+{
+ public class XmlTextWriterTests
+ {
+ public static IEnumerable