Add FoundryConnectionException for better network error handling in C# SDK #342
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When the Foundry Local service is unreachable, the C# SDK threw raw
HttpRequestException/SocketException. Other SDKs (JS, Python, Rust) already wrap these with user-friendly messages.Note: The CLI error message in the issue ("Exception fetching models from Azure Foundry catalog") originates from the closed-source Foundry CLI binary, not this repository.
Changes
New
FoundryConnectionException- Custom exception with clear guidance: "Could not connect to Foundry Local! Please check if the Foundry Local service is running and the host URL is correct."WrapHttpRequestAsynchelper - CatchesHttpRequestException(especially withSocketExceptioninner) and converts toFoundryConnectionExceptionUpdated all HTTP operations -
ListCatalogModelsAsync,GetCacheLocationAsync,ListCachedModelsAsync,DownloadModelAsync,LoadModelAsync,ListLoadedModelsAsync,UnloadModelAsyncDownloadModelWithProgressAsync- Uses inline handling (async iterators can't use wrapper pattern), yields error result instead of throwingUsage
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
aiinfra.pkgs.visualstudio.com/opt/hostedtoolcache/CodeQL/2.23.6/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp /opt/hostedtoolcache/CodeQL/2.23.6/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp(dns block)/usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/Foundry-Local/Foundry-Local/samples/cs/GettingStarted/cross-platform/FoundrySamplesXPlatform.sln --packages /home/REDACTED/work/Foundry-Local/.codeql-scratch/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/home/REDACTED/work/Foundry-Local/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/home/REDACTED/work/Foundry-Local/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot(dns block)/usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/Foundry-Local/Foundry-Local/samples/cs/GettingStarted/cross-platform/AudioTranscriptionExample/AudioTranscriptionExample.csproj --packages /home/REDACTED/work/Foundry-Local/.codeql-scratch/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/home/REDACTED/work/Foundry-Local/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/home/REDACTED/work/Foundry-Local/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot w/src/lib/compondiff w/sr�� w/src/lib/compon--irreversible-delete w/src/lib/compon-U0 t[bot](dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
This section details on the original issue you should resolve
<issue_title>[Offline] Have exception throwing (although still can be used) in no network scenario</issue_title>
<issue_description>I tried to use Foundry Local on plane (i.e. no network at all). It can be used, but will always list out exception (i.e. no blocking)
Both of the following situation will print out exceptions:
a. Ask for Model cache list:
b. Load Model:
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.