microsoft/garnet · error · ArgumentException
Azure Storage connection string is required to read/write to
Error message
Azure Storage connection string is required to read/write to Azure Storage
What it means
ArgumentException thrown by StreamProvider.GetStreamProvider when FileLocationType.AzureStorage is requested but the connectionString argument is null or empty. The factory cannot construct an AzureStreamProvider without credentials, so it refuses early with the parameter name 'connectionString'.
Source
Thrown at libs/common/StreamProvider.cs:137
/// Provides a StreamProvider instance
/// </summary>
public class StreamProviderFactory
{
/// <summary>
/// Get a StreamProvider instance
/// </summary>
/// <param name="locationType">Type of location of files the stream provider reads from / writes to</param>
/// <param name="connectionString">Connection string to Azure Storage, if applicable</param>
/// <param name="resourceAssembly">Assembly from which to load the embedded resource, if applicable.</param>
/// <param name="readOnly">Open file in read only mode</param>
/// <returns>StreamProvider instance</returns>
public static IStreamProvider GetStreamProvider(FileLocationType locationType, string connectionString = null, Assembly resourceAssembly = null, bool readOnly = false)
{
switch (locationType)
{
case FileLocationType.AzureStorage:
if (string.IsNullOrEmpty(connectionString))
throw new ArgumentException("Azure Storage connection string is required to read/write to Azure Storage", nameof(connectionString));
return new AzureStreamProvider(connectionString);
case FileLocationType.Local:
return new LocalFileStreamProvider(readOnly);
case FileLocationType.EmbeddedResource:
if (resourceAssembly == null)
throw new ArgumentException(
"Assembly is required to read from embedded resource", nameof(resourceAssembly));
return new EmbeddedResourceStreamProvider(resourceAssembly);
default:
throw new NotImplementedException();
}
}
}
/// <summary>
/// StreamProvider for reading / writing files in Azure Storage
/// </summary>
internal class AzureStreamProvider : StreamProviderBaseView on GitHub (pinned to 951b0fc683)
Solutions
- Provide a valid Azure Storage connection string as the connectionString argument.
- If the connection string comes from configuration, verify the config key exists and is loaded before calling GetStreamProvider.
- If using Managed Identity instead, switch the higher-level Options to use AzureStorageServiceUri rather than the AzureStorage location type path.
- If Azure storage was selected by mistake, use FileLocationType.Local instead.
Example fix
// before
var provider = StreamProvider.GetStreamProvider(FileLocationType.AzureStorage);
// after
var provider = StreamProvider.GetStreamProvider(
FileLocationType.AzureStorage,
connectionString: Environment.GetEnvironmentVariable("AZURE_STORAGE_CONN_STRING")); Defensive patterns
Strategy: validation
Validate before calling
IStreamProvider GetProviderSafely(FileLocationType type, string connStr = null, Assembly asm = null, bool readOnly = false)
{
if (type == FileLocationType.AzureStorage && string.IsNullOrEmpty(connStr))
throw new InvalidOperationException("AzureStorage requires a connection string. Set AZURE_STORAGE_CONN_STRING.");
return StreamProvider.GetStreamProvider(type, connStr, asm, readOnly);
} Try / catch
try
{
var provider = StreamProvider.GetStreamProvider(FileLocationType.AzureStorage, connectionString);
}
catch (ArgumentException ex) when (ex.ParamName == "connectionString")
{
logger.LogError("Azure Storage connection string missing. Check your configuration.");
throw;
} Prevention
- Centralize storage-provider creation in one factory method that validates inputs first.
- Fail fast at startup with a clear message if the Azure connection string env var is absent.
- Use a config schema validator that requires the connection string when device type is Azure.
When it happens
Trigger: Calling GetStreamProvider(FileLocationType.AzureStorage, connectionString: null) or omitting the connection string. Common in checkpoint/AOF configuration when the device type is set to AzureStorage but the storage connection string environment variable or config field is unset.
Common situations: Config file specifies AzureStorage device but the connection string is read from an environment variable that is not set in the deployment; a typo in the config key name; migration from local to Azure storage where the connection string was not yet provisioned.
Related errors
- Assembly is required to read from embedded resource
- Config file size {numBytesToWrite} is larger than the maximu
- Cannot use AzureStorage device without supplying storage-str
- Cannot use AzureStorage device with both storage-string and
- Elements collection cannot be empty.
AI-assisted analysis of microsoft/garnet@951b0fc683 (2026-08-13).
Data as JSON: /api/errors/a299faf3645d171b.
Report an issue: GitHub.