dotnet/reactive · error · ArgumentNullException
Value cannot be null. (Parameter 'optimizationInterfaces')
Error message
Value cannot be null. (Parameter 'optimizationInterfaces')
What it means
The same DisableOptimizations overload also validates the optimizationInterfaces parameter; passing a null Type[] throws ArgumentNullException naming 'optimizationInterfaces'. The wrapper needs the array (possibly empty) to know which optimizations to suppress.
Solutions
- Pass an empty array instead of null when no optimizations should be disabled
- Ensure the code building the Type[] returns Array.Empty<Type>() rather than null
- Check the variable for null before the call
Example fix
// before Type[] ifs = GetDisabledOptimizations(); // returns null var s = scheduler.DisableOptimizations(ifs); // after var ifs = GetDisabledOptimizations() ?? Array.Empty<Type>(); var s = scheduler.DisableOptimizations(ifs);
Defensive patterns
Strategy: validation
Validate before calling
optimizationInterfaces ??= Array.Empty<Type>();
Type guard
static bool HasInterfaceList(Type[] t) => t != null;
Try / catch
try { wrapped = scheduler.DisableOptimizations(list); }
catch (ArgumentNullException) { wrapped = scheduler.DisableOptimizations(Array.Empty<Type>()); } Prevention
- Return Array.Empty<Type>() instead of null from list builders
- Normalize params arrays with ?? Array.Empty<Type>() before calls
- Prefer overloads accepting IEnumerable with empty defaults
When it happens
Trigger: Calling scheduler.DisableOptimizations((Type[])null) or passing a variable typed Type[] that is null, typically built by a method that returned null instead of an empty array.
Common situations: Building the list of optimization interfaces dynamically; configuration-driven type lists that were never populated; API returning null for 'no restrictions'.
Related errors
- action (Parameter 'action')
- action (Parameter 'action')
- action (Parameter 'action')
- action (Parameter 'action')
- action (Parameter 'action')
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/392725565330c6c4.
Report an issue: GitHub.
Appendix: source
Thrown at Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Wrappers.cs:41
}
/// <summary>
/// Returns a scheduler that represents the original scheduler, without the specified set of interface-based optimizations (e.g. long running scheduling).
/// </summary>
/// <param name="scheduler">Scheduler to disable the specified optimizations for.</param>
/// <param name="optimizationInterfaces">Types of the optimization interfaces that have to be disabled.</param>
/// <returns>Proxy to the original scheduler but without the specified optimizations enabled.</returns>
/// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="optimizationInterfaces"/> is <c>null</c>.</exception>
public static IScheduler DisableOptimizations(this IScheduler scheduler, params Type[] optimizationInterfaces)
{
if (scheduler == null)
{
throw new ArgumentNullException(nameof(scheduler));
}
if (optimizationInterfaces == null)
{
throw new ArgumentNullException(nameof(optimizationInterfaces));
}
return new DisableOptimizationsScheduler(scheduler, optimizationInterfaces);
}
/// <summary>
/// Returns a scheduler that wraps the original scheduler, adding exception handling for scheduled actions.
/// </summary>
/// <typeparam name="TException">Type of the exception to check for.</typeparam>
/// <param name="scheduler">Scheduler to apply an exception filter for.</param>
/// <param name="handler">Handler that's run if an exception is caught. The exception will be rethrown if the handler returns false.</param>
/// <returns>Wrapper around the original scheduler, enforcing exception handling.</returns>
/// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="handler"/> is <c>null</c>.</exception>
public static IScheduler Catch<TException>(this IScheduler scheduler, Func<TException, bool> handler)
where TException : Exception
{
if (scheduler == null)
{View on GitHub (pinned to 94b5d5ab91)