.NET SDK TemporalClient.ConnectAsync for creating client
Use TemporalClient.ConnectAsync to create a Temporal Client in the .NET SDK. Connection options include the Temporal Server address, Namespace, and (optionally) TLS configuration. These options can be provided directly in code, loaded from environment variables, or loaded from a TOML configuration file using Temporalio.Client.EnvConfig helpers.
.NET SDK local development defaults
When running a Temporal Service locally, if you don't specify a host/port, most connections default to 127.0.0.1:7233 and the default Namespace.
.NET SDK TOML configuration file location
If you don't provide the configuration file path, the .NET SDK looks for it at the path ~/.config/temporalio/temporal.toml or the equivalent on your OS. You can use the environment variable TEMPORAL_CONFIG_FILE to specify a custom location.
Configuration file precedence in .NET SDK
Connection options set in configuration files have lower precedence than environment variables in the .NET SDK. If you set the same option in both the configuration file and as an environment variable, the environment variable value overrides the option set in the configuration file.
.NET SDK TOML configuration file profile structure
The TOML configuration file supports multiple profiles, each with its own set of connection options. Profiles are defined under [profile.profilename] sections. Common fields include address, namespace, api_key, tls (with client_cert_path and client_key_path), and grpc_meta (for custom gRPC headers).
ClientEnvConfig.LoadClientConnectOptions method in .NET SDK
Use ClientEnvConfig.LoadClientConnectOptions in the .NET SDK to load connection options. It can load a specific profile by name, or load the default profile if no profile name is specified. The method accepts ProfileLoadOptions parameter which can specify ConfigSource and Profile name.
.NET SDK environment variables for local development
For local development with .NET SDK, set TEMPORAL_NAMESPACE and TEMPORAL_ADDRESS environment variables. These can be omitted entirely since they default to 'default' namespace and 'localhost:7233' address.
Temporal Cloud connection requirements for .NET SDK
Connection to Temporal Cloud using the .NET SDK requires: credentials for authentication (API key or mTLS certificates), your Namespace and Account ID combination in format <namespace_id>.<account_id>, and the endpoint in format <namespace>.<account>.tmprl.cloud:7233.
.NET SDK environment variables for Temporal Cloud
To connect to Temporal Cloud with .NET SDK using environment variables, set: TEMPORAL_NAMESPACE (your Namespace and Account ID in format <namespace_id>.<account_id>), TEMPORAL_ADDRESS (gRPC endpoint), TEMPORAL_API_KEY (for API key auth), TEMPORAL_TLS_CLIENT_CERT_DATA or TEMPORAL_TLS_CLIENT_CERT_PATH (for mTLS), and TEMPORAL_TLS_CLIENT_KEY_DATA or TEMPORAL_TLS_CLIENT_KEY_PATH (for mTLS).
.NET SDK API key connection to Temporal Cloud
To connect to Temporal Cloud with API key in .NET SDK, call TemporalClient.ConnectAsync with TemporalClientConnectOptions specifying Namespace in format <namespace_id>.<account_id>, endpoint as the address parameter, and ApiKey property set to your API key value.
.NET SDK mTLS connection to Temporal Cloud
To connect to Temporal Cloud with mTLS in .NET SDK, call TemporalClient.ConnectAsync with TemporalClientConnectOptions specifying Namespace in format <namespace_id>.<account_id>, endpoint as the address parameter, and Tls property with ClientCert and ClientPrivateKey bytes read from certificate files.
.NET SDK API key update on existing connection
To update an API key on an existing Temporal Client connection in .NET SDK, update the value of the ApiKey property on the client's Connection object: myClient.Connection.ApiKey = myKeyUpdated;
.NET SDK mTLS certificate rotation
In .NET SDK, TlsOptions is not mutable on an existing connection. To rotate an mTLS client certificate without restarting the Worker, create a new TemporalClient with the new certificate using TemporalClient.ConnectAsync, then assign it to the running TemporalWorker's Client property: worker.Client = newClient. This replaces the connection for subsequent calls without interrupting calls already in flight.