microsoft/garnet · error · ArgumentException

Assembly is required to read from embedded resource

Error message

Assembly is required to read from embedded resource

What it means

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'.

Source

Thrown at libs/common/StreamProvider.cs:143

        /// </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 : StreamProviderBase
    {
        private readonly string _connectionString;
        private readonly AzureStorageNamedDeviceFactoryCreator azureStorageNamedDeviceFactoryCreator;

        public AzureStreamProvider(string connectionString)
        {

View on GitHub (pinned to 951b0fc683)

Solutions

  1. Pass the assembly that contains the embedded resource, e.g., resourceAssembly: Assembly.GetExecutingAssembly() or typeof(MyClass).Assembly.
  2. Verify the resource file is actually marked as 'Embedded Resource' in the .csproj / build action.
  3. If the resource lives in a different assembly, pass that assembly's reference explicitly.
  4. If embedded resources are not intended, switch to FileLocationType.Local and supply a file path.

Example fix

// before
var provider = StreamProvider.GetStreamProvider(FileLocationType.EmbeddedResource);

// after
var provider = StreamProvider.GetStreamProvider(
    FileLocationType.EmbeddedResource,
    resourceAssembly: Assembly.GetExecutingAssembly());
Defensive patterns

Strategy: validation

Validate before calling

IStreamProvider GetEmbeddedProvider(Assembly asm)
{
    if (asm == null)
        throw new InvalidOperationException("EmbeddedResource location type requires a non-null assembly.");
    return StreamProvider.GetStreamProvider(FileLocationType.EmbeddedResource, resourceAssembly: asm);
}

Try / catch

try
{
    var provider = StreamProvider.GetStreamProvider(FileLocationType.EmbeddedResource, resourceAssembly: asm);
}
catch (ArgumentException ex) when (ex.ParamName == "resourceAssembly")
{
    logger.LogError("Assembly is required for embedded resource stream provider.");
    throw;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of microsoft/garnet@951b0fc683 (2026-08-13). Data as JSON: /api/errors/92c1ec6a71bdd069. Report an issue: GitHub.