{"record":{"id":"a299faf3645d171b","repo":"microsoft/garnet","slug":"azure-storage-connection-string-is-required-to-rea","errorCode":null,"errorMessage":"Azure Storage connection string is required to read/write to Azure Storage","messagePattern":"Azure Storage connection string is required to read/write to Azure Storage","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"libs/common/StreamProvider.cs","lineNumber":137,"sourceCode":"    /// Provides a StreamProvider instance\n    /// </summary>\n    public class StreamProviderFactory\n    {\n        /// <summary>\n        /// Get a StreamProvider instance\n        /// </summary>\n        /// <param name=\"locationType\">Type of location of files the stream provider reads from / writes to</param>\n        /// <param name=\"connectionString\">Connection string to Azure Storage, if applicable</param>\n        /// <param name=\"resourceAssembly\">Assembly from which to load the embedded resource, if applicable.</param>\n        /// <param name=\"readOnly\">Open file in read only mode</param>\n        /// <returns>StreamProvider instance</returns>\n        public static IStreamProvider GetStreamProvider(FileLocationType locationType, string connectionString = null, Assembly resourceAssembly = null, bool readOnly = false)\n        {\n            switch (locationType)\n            {\n                case FileLocationType.AzureStorage:\n                    if (string.IsNullOrEmpty(connectionString))\n                        throw new ArgumentException(\"Azure Storage connection string is required to read/write to Azure Storage\", nameof(connectionString));\n                    return new AzureStreamProvider(connectionString);\n                case FileLocationType.Local:\n                    return new LocalFileStreamProvider(readOnly);\n                case FileLocationType.EmbeddedResource:\n                    if (resourceAssembly == null)\n                        throw new ArgumentException(\n                            \"Assembly is required to read from embedded resource\", nameof(resourceAssembly));\n                    return new EmbeddedResourceStreamProvider(resourceAssembly);\n                default:\n                    throw new NotImplementedException();\n            }\n        }\n    }\n\n    /// <summary>\n    /// StreamProvider for reading / writing files in Azure Storage\n    /// </summary>\n    internal class AzureStreamProvider : StreamProviderBase","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/microsoft/garnet/blob/951b0fc6838721f89d102c2bbe1b914e8d39d700/libs/common/StreamProvider.cs#L119-L155","documentation":"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'.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nvar provider = StreamProvider.GetStreamProvider(FileLocationType.AzureStorage);\n\n// after\nvar provider = StreamProvider.GetStreamProvider(\n    FileLocationType.AzureStorage,\n    connectionString: Environment.GetEnvironmentVariable(\"AZURE_STORAGE_CONN_STRING\"));","handlingStrategy":"validation","validationCode":"IStreamProvider GetProviderSafely(FileLocationType type, string connStr = null, Assembly asm = null, bool readOnly = false)\n{\n    if (type == FileLocationType.AzureStorage && string.IsNullOrEmpty(connStr))\n        throw new InvalidOperationException(\"AzureStorage requires a connection string. Set AZURE_STORAGE_CONN_STRING.\");\n    return StreamProvider.GetStreamProvider(type, connStr, asm, readOnly);\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    var provider = StreamProvider.GetStreamProvider(FileLocationType.AzureStorage, connectionString);\n}\ncatch (ArgumentException ex) when (ex.ParamName == \"connectionString\")\n{\n    logger.LogError(\"Azure Storage connection string missing. Check your configuration.\");\n    throw;\n}","preventionTips":["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."],"tags":["config","azure-storage","validation","argument","streamprovider"],"backgroundTag":null,"analyzedSha":"951b0fc6838721f89d102c2bbe1b914e8d39d700","analyzedAt":"2026-08-13T19:01:32.939Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}