From 9ca092a114c56592a2bd93f111e98867401ea5ad Mon Sep 17 00:00:00 2001 From: ladeak Date: Thu, 8 May 2025 20:54:09 +0200 Subject: [PATCH 1/2] dotnet-dump and dotnet-symbol returns 407 behind a proxy when downloading symbols. Setting the default network credentials before HttpClient is set. Optionally HttpSymbolStore could create a custom HttpClientHandler, but based on the remarks https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclienthandler.usedefaultcredentials?view=net-9.0 this is only desired for client applications, while not sure how this project is used otherwise. --- src/Tools/dotnet-dump/Analyzer.cs | 3 +++ src/Tools/dotnet-symbol/Program.cs | 9 +++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Tools/dotnet-dump/Analyzer.cs b/src/Tools/dotnet-dump/Analyzer.cs index 730d5fa5e2..04481b3dbc 100644 --- a/src/Tools/dotnet-dump/Analyzer.cs +++ b/src/Tools/dotnet-dump/Analyzer.cs @@ -3,6 +3,8 @@ using System; using System.IO; +using System.Net; +using System.Net.Http; using System.Reflection; using System.Runtime.InteropServices; using System.Security; @@ -102,6 +104,7 @@ or NotSupportedException contextService.SetCurrentTarget(target); // Automatically enable symbol server support, default cache and search for symbols in the dump directory + HttpClient.DefaultProxy.Credentials = CredentialCache.DefaultCredentials; symbolService.AddSymbolServer(retryCount: 3); symbolService.AddCachePath(symbolService.DefaultSymbolCache); symbolService.AddDirectoryPath(Path.GetDirectoryName(dump_path.FullName)); diff --git a/src/Tools/dotnet-symbol/Program.cs b/src/Tools/dotnet-symbol/Program.cs index 8aa07ddeb7..9b587bc606 100644 --- a/src/Tools/dotnet-symbol/Program.cs +++ b/src/Tools/dotnet-symbol/Program.cs @@ -5,6 +5,8 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Net; +using System.Net.Http; using System.Net.Http.Headers; using System.Runtime.InteropServices; using System.Threading; @@ -68,7 +70,7 @@ public static void Main(string[] args) program.SymbolServers.Add(new ServerInfo { Uri = uri, PersonalAccessToken = null }); break; - case "--internal-server": + case "--internal-server": Uri.TryCreate("https://symweb.azurefd.net/", UriKind.Absolute, out uri); program.SymbolServers.Add(new ServerInfo { Uri = uri, PersonalAccessToken = null, InternalSymwebServer = true }); break; @@ -263,7 +265,7 @@ internal async Task DownloadFiles() private Microsoft.SymbolStore.SymbolStores.SymbolStore BuildSymbolStore() { Microsoft.SymbolStore.SymbolStores.SymbolStore store = null; - + HttpClient.DefaultProxy.Credentials = CredentialCache.DefaultCredentials; foreach (ServerInfo server in ((IEnumerable)SymbolServers).Reverse()) { if (server.InternalSymwebServer) @@ -597,8 +599,7 @@ internal void VerifyCoreDump() private IEnumerable GetInputFiles() { - IEnumerable inputFiles = InputFilePaths.SelectMany((string file) => - { + IEnumerable inputFiles = InputFilePaths.SelectMany((string file) => { string directory = Path.GetDirectoryName(file); string pattern = Path.GetFileName(file); return Directory.EnumerateFiles(string.IsNullOrWhiteSpace(directory) ? "." : directory, pattern, From c9cb4c901900014e0a988ae10412ced52dfb7eca Mon Sep 17 00:00:00 2001 From: ladeak Date: Fri, 9 May 2025 21:13:42 +0200 Subject: [PATCH 2/2] Custom new HttpClientHandler() when HttpSymbolServer is built on .netstandard --- .../SymbolStores/HttpSymbolStore.cs | 10 +++++++++- src/Tools/dotnet-dump/Analyzer.cs | 4 ---- src/Tools/dotnet-symbol/Program.cs | 4 +--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.SymbolStore/SymbolStores/HttpSymbolStore.cs b/src/Microsoft.SymbolStore/SymbolStores/HttpSymbolStore.cs index 5887261547..32b9856802 100644 --- a/src/Microsoft.SymbolStore/SymbolStores/HttpSymbolStore.cs +++ b/src/Microsoft.SymbolStore/SymbolStores/HttpSymbolStore.cs @@ -67,7 +67,15 @@ public HttpSymbolStore(ITracer tracer, SymbolStore backingStore, Uri symbolServe _authenticationFunc = authenticationFunc; // Create client - _client = new HttpClient +#if NETSTANDARD2_0 + _client = new HttpClient(new HttpClientHandler() + { + UseProxy = true, + DefaultProxyCredentials = CredentialCache.DefaultNetworkCredentials, + }) +#else + _client = new HttpClient() +#endif { Timeout = TimeSpan.FromMinutes(4) }; diff --git a/src/Tools/dotnet-dump/Analyzer.cs b/src/Tools/dotnet-dump/Analyzer.cs index 04481b3dbc..1e887b527a 100644 --- a/src/Tools/dotnet-dump/Analyzer.cs +++ b/src/Tools/dotnet-dump/Analyzer.cs @@ -3,13 +3,10 @@ using System; using System.IO; -using System.Net; -using System.Net.Http; using System.Reflection; using System.Runtime.InteropServices; using System.Security; using System.Threading; -using System.Threading.Tasks; using Microsoft.Diagnostics.DebugServices; using Microsoft.Diagnostics.DebugServices.Implementation; using Microsoft.Diagnostics.ExtensionCommands; @@ -104,7 +101,6 @@ or NotSupportedException contextService.SetCurrentTarget(target); // Automatically enable symbol server support, default cache and search for symbols in the dump directory - HttpClient.DefaultProxy.Credentials = CredentialCache.DefaultCredentials; symbolService.AddSymbolServer(retryCount: 3); symbolService.AddCachePath(symbolService.DefaultSymbolCache); symbolService.AddDirectoryPath(Path.GetDirectoryName(dump_path.FullName)); diff --git a/src/Tools/dotnet-symbol/Program.cs b/src/Tools/dotnet-symbol/Program.cs index 9b587bc606..60a5bd5051 100644 --- a/src/Tools/dotnet-symbol/Program.cs +++ b/src/Tools/dotnet-symbol/Program.cs @@ -5,8 +5,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using System.Net; -using System.Net.Http; using System.Net.Http.Headers; using System.Runtime.InteropServices; using System.Threading; @@ -265,7 +263,7 @@ internal async Task DownloadFiles() private Microsoft.SymbolStore.SymbolStores.SymbolStore BuildSymbolStore() { Microsoft.SymbolStore.SymbolStores.SymbolStore store = null; - HttpClient.DefaultProxy.Credentials = CredentialCache.DefaultCredentials; + foreach (ServerInfo server in ((IEnumerable)SymbolServers).Reverse()) { if (server.InternalSymwebServer)