dotnet/orleans · error · ArgumentNullException

Value cannot be null. (Parameter 'logger')

Error message

Value cannot be null. (Parameter 'logger')

What it means

Thrown by the AzureTableDataManager<T> constructor when the logger argument is null. The manager logs every storage operation, so it rejects a missing logger up front.

Source

Thrown at src/Azure/Shared/Storage/AzureTableDataManager.cs:64

        public string TableName { get; }

        /// <summary> Logger for this table manager instance. </summary>
        protected internal ILogger Logger { get; }

        public AzureStoragePolicyOptions StoragePolicyOptions { get; }

        public TableClient Table { get; private set; } = null!;

        /// <summary>
        /// Creates a new <see cref="AzureTableDataManager{T}"/> instance.
        /// </summary>
        /// <param name="options">Storage configuration.</param>
        /// <param name="logger">Logger to use.</param>
        public AzureTableDataManager(AzureStorageOperationOptions options, ILogger logger)
        {
            this.options = options ?? throw new ArgumentNullException(nameof(options));

            Logger = logger ?? throw new ArgumentNullException(nameof(logger));
            TableName = options.TableName ?? throw new ArgumentNullException(nameof(options.TableName));
            StoragePolicyOptions = options.StoragePolicyOptions ?? throw new ArgumentNullException(nameof(options.StoragePolicyOptions));

            AzureTableUtils.ValidateTableName(TableName);
        }

        /// <summary>
        /// Connects to, or creates and initializes a new Azure table if it does not already exist.
        /// </summary>
        /// <returns>Completion promise for this operation.</returns>
        public async Task InitTableAsync()
        {
            const string operation = "InitTable";
            var startTime = DateTime.UtcNow;

            try
            {
                TableServiceClient tableCreationClient = await GetCloudTableCreationClientAsync();

View on GitHub (pinned to fca799fa70)

Solutions

  1. Pass a non-null ILogger (typically ILogger<T> resolved from DI, or NullLogger.Instance for tests).
  2. Use a NullLogger as a safe fallback in unit tests.
  3. Resolve the logger from the DI container.

Example fix

// before
var mgr = new AzureTableDataManager<MyEntity>(options, null);
// after
var logger = services.GetRequiredService<ILogger<AzureTableDataManager<MyEntity>>>();
var mgr = new AzureTableDataManager<MyEntity>(options, logger);
Defensive patterns

Strategy: validation

Validate before calling

ILogger log = logger ?? NullLogger<AzureTableDataManager<T>>.Instance;
var mgr = new AzureTableDataManager<T>(options, log);

Type guard

static bool HasLogger(ILogger? l) => l is not null;

Try / catch

catch (ArgumentNullException ex) when (ex.ParamName == "logger") { /* inject ILogger<T> or use NullLogger */ }

Prevention

When it happens

Trigger: Constructing AzureTableDataManager<T> with a null ILogger — e.g. in a context where ILogger<T> was not resolved from DI.

Common situations: Manual construction outside DI; tests without a logger factory; refactoring that dropped logger injection.

Related errors


AI-assisted analysis of dotnet/orleans@fca799fa70 (2026-08-13). Data as JSON: /api/errors/e5a92b93aec3691a. Report an issue: GitHub.