Add FoundryConnectionException for better network error handling in C# SDK#342
Draft
Add FoundryConnectionException for better network error handling in C# SDK#342
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…dling Co-authored-by: natke <[email protected]>
…ProgressAsync Co-authored-by: natke <[email protected]>
Copilot
AI
changed the title
[WIP] Fix exception throwing in offline scenario
Add FoundryConnectionException for better network error handling in C# SDK
Dec 4, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.