dotnet/wpf · error · InvalidOperationException
SR.Effect_No_ContextInputSource
Error message
SR.Effect_No_ContextInputSource
What it means
BitmapEffect.GetOutput(input) was called with input.Input set to the sentinel BitmapEffectInput.ContextInputSource. That sentinel means 'take the source from the ambient rendering context', which GetOutput cannot resolve, so it throws InvalidOperationException with a formatted SR.Effect_No_ContextInputSource message.
Solutions
- Assign a concrete BitmapSource to input.Input before calling GetOutput
- Let the effect pipeline supply the context source itself instead of evaluating an input that references ContextInputSource
- In tests, build the input with an explicit rendered BitmapSource
- Check for code paths that reset Input back to ContextInputSource
Example fix
// before
var input = new BitmapEffectInput { Input = BitmapEffectInput.ContextInputSource };
var output = effect.GetOutput(input); // throws
// after
var input = new BitmapEffectInput { Input = renderedSource }; // real BitmapSource
var output = effect.GetOutput(input); Defensive patterns
Strategy: validation
Validate before calling
if (input?.Input == null || input.Input == BitmapEffectInput.ContextInputSource)
throw new ArgumentException("Input must be a concrete BitmapSource, not ContextInputSource", nameof(input));
var output = effect.GetOutput(input); Type guard
static bool HasRealSource(BitmapEffectInput input) =>
input != null && input.Input != null && input.Input != BitmapEffectInput.ContextInputSource; Try / catch
try { var output = effect.GetOutput(input); }
catch (InvalidOperationException ex) when (ex.Message.Contains("context"))
{
// rebuild the input with an explicit BitmapSource
} Prevention
- Treat BitmapEffectInput.ContextInputSource as pipeline-internal only
- In tests and off-context evaluation, always use explicit BitmapSource instances
- Guard shared inputs against being reset to the sentinel
When it happens
Trigger: Calling GetOutput on a BitmapEffectInput that was never given a real source and still holds the ContextInputSource default/sentinel value.
Common situations: Copying the default input out of a live effect pipeline and evaluating it later, off-context; unit tests constructing inputs manually without realizing ContextInputSource is a placeholder, not a real BitmapSource.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Animation_Invalid_DefaultValue
- Cannot remove signature from read-only file.
- Image_EncoderNoColorContext
- Image_EncoderNoGlobalMetadata
- Image_EncoderNoGlobalThumbnail
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/2877378d7a76a31e.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Effects/BitmapEffect.cs:102
#region Public Methods
/// <summary>
/// This returns the output at index 0
/// </summary>
[Obsolete(MS.Internal.Media.VisualTreeUtils.BitmapEffectObsoleteMessage)]
public BitmapSource GetOutput(BitmapEffectInput input)
{
ArgumentNullException.ThrowIfNull(input);
// if we don't have the input set, we should not be calling the output property
if (input.Input == null)
{
throw new ArgumentException(SR.Effect_No_InputSource, nameof(input));
}
if (input.Input == BitmapEffectInput.ContextInputSource)
{
throw new InvalidOperationException(SR.Format(SR.Effect_No_ContextInputSource, null));
}
return input.Input.Clone();
}
#endregion
#region Internal Methods
/// <summary>
/// True if the effect can be emulated by the Effect pipeline. Derived classes
/// can override this method to indicate that they can be emulated using the ImageEffect
/// pipeline. If a derived class returns true it needs to also implement the GetEmulatingImageEffect
/// property to provide an emulating ImageEffect.
/// </summary>
internal virtual bool CanBeEmulatedUsingEffectPipeline()
{
return false;
}View on GitHub (pinned to 81131a70a4)