Fixing the BigQuery .NET Proxy Bypass: Credential vs GoogleCredential
If your C# application runs behind a proxy, you have probably run into an annoying issue with the Google BigQuery client libraries: your BigQuery data calls route through the proxy perfectly by setting the HttpClientFactory property on the BigQueryClientBuilder, but your authentication and token refresh requests ignore the proxy entirely and attempt to hit the standard network, causing timeouts.
The Solution
To resolve this, assign a proxy-wrapped credential to the GoogleCredential property instead of the legacy Credential property on the client builder.
Example code:
using System.Net; using Google.Apis.Auth.OAuth2; using Google.Apis.Http; using Google.Cloud.BigQuery.V2; // 1. Configure your corporate proxy IWebProxy proxySettings = new WebProxy("http://your-proxy-host:8080", bypassOnLocal: true) { Credentials = new NetworkCredential("username", "password") }; // 2. Wrap it inside Google's API HttpClientFactory HttpClientFactory proxyClientFactory = HttpClientFactory.ForProxy(proxySettings); // 3. Load credentials and attach the proxy factory to the Auth layer GoogleCredential credential = await GoogleCredential.FromFileAsync("path/to/service-account.json"); credential = credential.CreateWithHttpClientFactory(proxyClientFactory); // 4. Construct the client using the correct strongly-typed property BigQueryClient bigQueryClient = new BigQueryClientBuilder { ProjectId = "your-google-cloud-project-id", HttpClientFactory = proxyClientFactory, // Proxies BigQuery data calls GoogleCredential = credential // CRITICAL: Proxies Auth/token calls }.Build();
The Key Difference
builder.Credential = credential; $\rightarrow$ Fails to route authentication traffic through the proxy network.
builder.GoogleCredential = credential; $\rightarrow$ Successfully routes both BigQuery data calls and OAuth token requests through the proxy.















