C
C#2y ago
oe

❔ C# Exceptions Not Caught?

Why is this code causing Visual Studio to break if it is being ran in a try catch? It takes me here and shows me this exception:
System.Net.Http.HttpRequestException: 'The proxy tunnel request to proxy '' failed with status code '502'."'

C:\Users\FRZ\AppData\Local\SourceServer\89eb5aeb9b5e4245c273d7fede24aa2abe75483baa9ebc06da5a3ca0b1aba702\src\libraries\System.Private.CoreLib\src\System\Threading\Tasks\ValueTask.cs

[DebuggerBrowsable(DebuggerBrowsableState.Never)] // prevent debugger evaluation from invalidating an underling IValueTaskSource<T>
public TResult Result
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
object? obj = _obj;
Debug.Assert(obj == null || obj is Task<TResult> || obj is IValueTaskSource<TResult>);

if (obj == null)
{
return _result!;
}

if (obj is Task<TResult> t)
{
TaskAwaiter.ValidateEnd(t);
return t.ResultOnSuccess;
}

return Unsafe.As<IValueTaskSource<TResult>>(obj).GetResult(_token);
}
}
System.Net.Http.HttpRequestException: 'The proxy tunnel request to proxy '' failed with status code '502'."'

C:\Users\FRZ\AppData\Local\SourceServer\89eb5aeb9b5e4245c273d7fede24aa2abe75483baa9ebc06da5a3ca0b1aba702\src\libraries\System.Private.CoreLib\src\System\Threading\Tasks\ValueTask.cs

[DebuggerBrowsable(DebuggerBrowsableState.Never)] // prevent debugger evaluation from invalidating an underling IValueTaskSource<T>
public TResult Result
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
object? obj = _obj;
Debug.Assert(obj == null || obj is Task<TResult> || obj is IValueTaskSource<TResult>);

if (obj == null)
{
return _result!;
}

if (obj is Task<TResult> t)
{
TaskAwaiter.ValidateEnd(t);
return t.ResultOnSuccess;
}

return Unsafe.As<IValueTaskSource<TResult>>(obj).GetResult(_token);
}
}
The issue is occuring here: HttpResponseMessage httpResp = await Client.SendAsync(httpReq);
public static async Task<string?> GetShopHtml(string shopUrl)
{
using var httpReq = new HttpRequestMessage(HttpMethod.Get, shopUrl);

HttpResponseMessage httpResp = await Client.SendAsync(httpReq);
public static async Task<string?> GetShopHtml(string shopUrl)
{
using var httpReq = new HttpRequestMessage(HttpMethod.Get, shopUrl);

HttpResponseMessage httpResp = await Client.SendAsync(httpReq);
{
string shopHtml = await TestRequests.GetShopHtml(shopUrl);
collection = _scanner.ExtractNodes(shopHtml!);
}
catch (Exception ex)
{
_logger.LogError($"Error while scraping {shopUrl}, added to errors json file.");
await File.AppendAllTextAsync("Errors.json", ex.ToString());
}
{
string shopHtml = await TestRequests.GetShopHtml(shopUrl);
collection = _scanner.ExtractNodes(shopHtml!);
}
catch (Exception ex)
{
_logger.LogError($"Error while scraping {shopUrl}, added to errors json file.");
await File.AppendAllTextAsync("Errors.json", ex.ToString());
}
Regardless of the exception type, it should not be breaking in Visual Studio? I am running Visual Studio 2022 preview version
5 Replies
oe
oeOP2y ago
Unfortunately I already started coding in .NET 8.0 (mistake) for the project so I am stuck with this preview version. Is it caused by the preview version and does anyone know if theres a setting that I can disable for this or something?
Jimmacle
Jimmacle2y ago
depending on your debugging options VS will break on exceptions regardless of whether they're in a try/catch or not i don't use VS myself so i'm not sure exactly which option, but that's probably your problem
oe
oeOP2y ago
hmm, i didn't toggle anything, and i cant remember this happening in previous versions of VS @jimmacle i checked if HttpExceptions were in the break when exception is thrown configuration and they were not
reflectronic
reflectronic2y ago
you can always change it in the project properties
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server