{"record":{"id":"92c1ec6a71bdd069","repo":"microsoft/garnet","slug":"assembly-is-required-to-read-from-embedded-resourc","errorCode":null,"errorMessage":"Assembly is required to read from embedded resource","messagePattern":"Assembly is required to read from embedded resource","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"libs/common/StreamProvider.cs","lineNumber":143,"sourceCode":"        /// </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\n    {\n        private readonly string _connectionString;\n        private readonly AzureStorageNamedDeviceFactoryCreator azureStorageNamedDeviceFactoryCreator;\n\n        public AzureStreamProvider(string connectionString)\n        {","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/microsoft/garnet/blob/951b0fc6838721f89d102c2bbe1b914e8d39d700/libs/common/StreamProvider.cs#L125-L161","documentation":"ArgumentException thrown by StreamProvider.GetStreamProvider when FileLocationType.EmbeddedResource is requested but the resourceAssembly argument is null. The EmbeddedResourceStreamProvider needs an Assembly to locate the embedded resource manifest, so the factory refuses early with parameter name 'resourceAssembly'.","triggerScenarios":"Calling GetStreamProvider(FileLocationType.EmbeddedResource, resourceAssembly: null). Typically occurs when a config or data file is expected to be bundled as an embedded resource in a specific assembly but the caller forgot to pass Assembly.GetExecutingAssembly() or equivalent.","commonSituations":"Loading default config or seed data from an embedded resource during startup; the assembly reference was refactored away or passed as null by mistake; test harness calls the API without supplying the assembly under test.","solutions":["Pass the assembly that contains the embedded resource, e.g., resourceAssembly: Assembly.GetExecutingAssembly() or typeof(MyClass).Assembly.","Verify the resource file is actually marked as 'Embedded Resource' in the .csproj / build action.","If the resource lives in a different assembly, pass that assembly's reference explicitly.","If embedded resources are not intended, switch to FileLocationType.Local and supply a file path."],"exampleFix":"// before\nvar provider = StreamProvider.GetStreamProvider(FileLocationType.EmbeddedResource);\n\n// after\nvar provider = StreamProvider.GetStreamProvider(\n    FileLocationType.EmbeddedResource,\n    resourceAssembly: Assembly.GetExecutingAssembly());","handlingStrategy":"validation","validationCode":"IStreamProvider GetEmbeddedProvider(Assembly asm)\n{\n    if (asm == null)\n        throw new InvalidOperationException(\"EmbeddedResource location type requires a non-null assembly.\");\n    return StreamProvider.GetStreamProvider(FileLocationType.EmbeddedResource, resourceAssembly: asm);\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    var provider = StreamProvider.GetStreamProvider(FileLocationType.EmbeddedResource, resourceAssembly: asm);\n}\ncatch (ArgumentException ex) when (ex.ParamName == \"resourceAssembly\")\n{\n    logger.LogError(\"Assembly is required for embedded resource stream provider.\");\n    throw;\n}","preventionTips":["Always pass Assembly.GetExecutingAssembly() (or the owning assembly) when requesting the embedded-resource provider.","Verify the embedded resource exists via asm.GetManifestResourceNames() before calling GetStreamProvider."],"tags":["config","embedded-resource","validation","argument","streamprovider"],"backgroundTag":null,"analyzedSha":"951b0fc6838721f89d102c2bbe1b914e8d39d700","analyzedAt":"2026-08-13T19:01:32.939Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}