From cc70662baf4e2b0f0ebc03ee5b8e109a4419b3dd Mon Sep 17 00:00:00 2001 From: Radek Zikmund Date: Mon, 10 Oct 2022 16:59:25 +0200 Subject: [PATCH 1/5] Feedback from #8467 --- .../Overview/httpversion_version10.cs | 62 +++++++++---------- xml/System.Net/WebProxy.xml | 6 +- 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/snippets/csharp/System.Net/HttpVersion/Overview/httpversion_version10.cs b/snippets/csharp/System.Net/HttpVersion/Overview/httpversion_version10.cs index d92fd0a2d2d..2e35f758d4e 100644 --- a/snippets/csharp/System.Net/HttpVersion/Overview/httpversion_version10.cs +++ b/snippets/csharp/System.Net/HttpVersion/Overview/httpversion_version10.cs @@ -13,38 +13,38 @@ The changed Version and the 'Version' of the response object are displayed. class HttpVersion_Version10 { - public static void Main() - { - try - { -// - // HttpClient lifecycle management best practices: - // https://learn.microsoft.com/dotnet/fundamentals/networking/http/httpclient-guidelines#recommended-use - HttpClient client = new HttpClient(); + public static void Main() + { + try + { + // + // HttpClient lifecycle management best practices: + // https://learn.microsoft.com/dotnet/fundamentals/networking/http/httpclient-guidelines#recommended-use + using HttpClient client = new HttpClient(); - HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://www.microsoft.com"); - Console.WriteLine("Default HTTP request version is {0}", request.Version); + using HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://www.microsoft.com"); + Console.WriteLine("Default HTTP request version is {0}", request.Version); - request.Version = HttpVersion.Version10; - Console.WriteLine("Request version after assignment is {0}", request.Version); + request.Version = HttpVersion.Version10; + Console.WriteLine("Request version after assignment is {0}", request.Version); - HttpResponseMessage response = client.Send(request); - Console.WriteLine("Response HTTP version {0}", response.Version); -// - Console.WriteLine("\nPress 'Enter' Key to Continue.............."); - Console.Read(); - } - catch(HttpRequestException e) - { - Console.WriteLine("HttpRequestException Caught!"); - Console.WriteLine("Message :{0} ",e.Message); - Console.WriteLine("Source :{0} ",e.Source); - } - catch(Exception e) - { - Console.WriteLine("Exception Caught!"); - Console.WriteLine("Source :{0}" , e.Source); - Console.WriteLine("Message :{0}" , e.Message); - } - } + HttpResponseMessage response = client.Send(request); + Console.WriteLine("Response HTTP version {0}", response.Version); + // + Console.WriteLine("\nPress 'Enter' Key to Continue.............."); + Console.Read(); + } + catch (HttpRequestException e) + { + Console.WriteLine("HttpRequestException Caught!"); + Console.WriteLine("Message :{0} ", e.Message); + Console.WriteLine("Source :{0} ", e.Source); + } + catch (Exception e) + { + Console.WriteLine("Exception Caught!"); + Console.WriteLine("Source :{0}", e.Source); + Console.WriteLine("Message :{0}", e.Message); + } + } } diff --git a/xml/System.Net/WebProxy.xml b/xml/System.Net/WebProxy.xml index 40ce40fd986..c34704b6a2a 100644 --- a/xml/System.Net/WebProxy.xml +++ b/xml/System.Net/WebProxy.xml @@ -80,7 +80,7 @@ ## Examples - The following code example sets up instance with a instance. The instance uses the proxy to connect to external Internet resources. (For an example that demonstrates using the WPAD feature, see the documentation for the class.) + The following code example sets up an instance with a instance. The instance uses the proxy to connect to external Internet resources. (For an example that demonstrates using the WPAD feature, see the documentation for the class.) :::code language="cpp" source="~/snippets/cpp/VS_Snippets_Remoting/Classic WebProxy Example/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System.Net/WebProxy/Overview/source.cs" id="Snippet1"::: @@ -1147,7 +1147,8 @@ Applications should use the property instead of the method. - +> [!NOTE] +> This property is not supported on .NET Core. ## Examples The following code example demonstrates calling this method. @@ -1157,6 +1158,7 @@ ]]> + On .NET Core. From 548b6be5b032ade21c64aa23b202c2e3e8068ab1 Mon Sep 17 00:00:00 2001 From: Radek Zikmund Date: Mon, 10 Oct 2022 17:00:52 +0200 Subject: [PATCH 2/5] Feedback from #8482 --- xml/System.Net.NetworkInformation/Ping.xml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/xml/System.Net.NetworkInformation/Ping.xml b/xml/System.Net.NetworkInformation/Ping.xml index e872f694e01..d877dc548bc 100644 --- a/xml/System.Net.NetworkInformation/Ping.xml +++ b/xml/System.Net.NetworkInformation/Ping.xml @@ -1775,10 +1775,7 @@ methods. - -> [!NOTE] -> The IP address returned by any of the methods can originate from a malicious remote computer. Do not connect to the remote computer using this. Use DNS to determine the IP address of the machine to which you want to connect. +The IP address returned by any of the methods can originate from a malicious remote computer. Do not connect to the remote computer using this. Use DNS to determine the IP address of the machine to which you want to connect. ]]> From cb579bfbb3e58a8c7ded0f35c38c2e8a49f0fdfa Mon Sep 17 00:00:00 2001 From: Radek Zikmund Date: Mon, 10 Oct 2022 17:03:16 +0200 Subject: [PATCH 3/5] Feedback from #8484 --- xml/System.Net.Http/ByteArrayContent.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xml/System.Net.Http/ByteArrayContent.xml b/xml/System.Net.Http/ByteArrayContent.xml index 926b71c2f60..5a727ca8503 100644 --- a/xml/System.Net.Http/ByteArrayContent.xml +++ b/xml/System.Net.Http/ByteArrayContent.xml @@ -83,7 +83,7 @@ class does not internally copy the provided byte array but keeps a reference to it instead. Callers should not modify the data in the array until the content is sent. +The class does not internally copy the provided byte array but keeps a reference to it instead. Callers should not modify the data in the array until after the content is sent. ]]> From e1a7f75d028abca85db2daf4530c22f89b13a005 Mon Sep 17 00:00:00 2001 From: Radek Zikmund Date: Mon, 10 Oct 2022 17:04:28 +0200 Subject: [PATCH 4/5] Feedback from #8460 --- .../csharp/System.Net.Sockets/TcpClient/Overview/tcpclient.cs | 2 +- .../System.Net.Sockets/TcpListener/Overview/tcpserver.cs | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/snippets/csharp/System.Net.Sockets/TcpClient/Overview/tcpclient.cs b/snippets/csharp/System.Net.Sockets/TcpClient/Overview/tcpclient.cs index bf021c270e6..f195a9dbbe4 100644 --- a/snippets/csharp/System.Net.Sockets/TcpClient/Overview/tcpclient.cs +++ b/snippets/csharp/System.Net.Sockets/TcpClient/Overview/tcpclient.cs @@ -66,7 +66,7 @@ static void Connect(String server, String message) // combination. Int32 port = 13000; - // Prefer using declaration to ensure the instance is Disposed later. + // Prefer a using declaration to ensure the instance is Disposed later. using TcpClient client = new TcpClient(server, port); // Translate the passed message into ASCII and store it as a Byte array. diff --git a/snippets/csharp/System.Net.Sockets/TcpListener/Overview/tcpserver.cs b/snippets/csharp/System.Net.Sockets/TcpListener/Overview/tcpserver.cs index b107d91f0e7..3958f30ae72 100644 --- a/snippets/csharp/System.Net.Sockets/TcpListener/Overview/tcpserver.cs +++ b/snippets/csharp/System.Net.Sockets/TcpListener/Overview/tcpserver.cs @@ -74,9 +74,6 @@ public static void Main() stream.Write(msg, 0, msg.Length); Console.WriteLine("Sent: {0}", data); } - - // Shutdown and end the connection - client.Close(); } } catch(SocketException e) From 2a29363b83c7c8d90ac4dca885c5d16446ee8378 Mon Sep 17 00:00:00 2001 From: Radek Zikmund Date: Mon, 10 Oct 2022 17:36:59 +0200 Subject: [PATCH 5/5] More fixes --- .../Overview/httpversion_version10.cs | 2 +- .../VB/httpversion_version10.vb | 18 ++++++++++-------- xml/System.Net.Http/ByteArrayContent.xml | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/snippets/csharp/System.Net/HttpVersion/Overview/httpversion_version10.cs b/snippets/csharp/System.Net/HttpVersion/Overview/httpversion_version10.cs index 2e35f758d4e..38103744c64 100644 --- a/snippets/csharp/System.Net/HttpVersion/Overview/httpversion_version10.cs +++ b/snippets/csharp/System.Net/HttpVersion/Overview/httpversion_version10.cs @@ -28,7 +28,7 @@ public static void Main() request.Version = HttpVersion.Version10; Console.WriteLine("Request version after assignment is {0}", request.Version); - HttpResponseMessage response = client.Send(request); + using HttpResponseMessage response = client.Send(request); Console.WriteLine("Response HTTP version {0}", response.Version); // Console.WriteLine("\nPress 'Enter' Key to Continue.............."); diff --git a/snippets/visualbasic/VS_Snippets_Remoting/HttpVersion_Version10/VB/httpversion_version10.vb b/snippets/visualbasic/VS_Snippets_Remoting/HttpVersion_Version10/VB/httpversion_version10.vb index 29311e8a3d5..f91f43136fd 100644 --- a/snippets/visualbasic/VS_Snippets_Remoting/HttpVersion_Version10/VB/httpversion_version10.vb +++ b/snippets/visualbasic/VS_Snippets_Remoting/HttpVersion_Version10/VB/httpversion_version10.vb @@ -17,16 +17,18 @@ Class HttpVersion_Version10 ' ' HttpClient lifecycle management best practices: ' https://learn.microsoft.com/dotnet/fundamentals/networking/http/httpclient-guidelines#recommended-use - Dim client As New HttpClient() + Using client As New HttpClient() + Using request As New HttpRequestMessage(HttpMethod.Get, "http://www.microsoft.com") + Console.WriteLine("Default HTTP request version is {0}", request.Version) - Dim request As New HttpRequestMessage(HttpMethod.Get, "http://www.microsoft.com") - Console.WriteLine("Default HTTP request version is {0}", request.Version) + request.Version = HttpVersion.Version10 + Console.WriteLine("Request version after assignment is {0}", request.Version) - request.Version = HttpVersion.Version10 - Console.WriteLine("Request version after assignment is {0}", request.Version) - - Dim response As HttpResponseMessage = client.Send(request) - Console.WriteLine("Response HTTP version {0}", response.Version) + Using response As HttpResponseMessage = client.Send(request) + Console.WriteLine("Response HTTP version {0}", response.Version) + End Using + End Using + End Using ' Console.WriteLine(ControlChars.Cr + "Press 'Enter' Key to Continue..............") Console.Read() diff --git a/xml/System.Net.Http/ByteArrayContent.xml b/xml/System.Net.Http/ByteArrayContent.xml index 5a727ca8503..e44dce5d5dd 100644 --- a/xml/System.Net.Http/ByteArrayContent.xml +++ b/xml/System.Net.Http/ByteArrayContent.xml @@ -129,7 +129,7 @@ The class does not internally copy the p class does not internally copy the provided byte array but keeps a reference to it instead. Callers should not modify the data in the array until the content is sent. +The class does not internally copy the provided byte array but keeps a reference to it instead. Callers should not modify the data in the array until after the content is sent. Only the range specified by the `offset` parameter and the `count` parameter is used as content.