dotnet/wpf · error · InvalidOperationException
SR.Image_NoArgument (Transform)
Error message
SR.Image_NoArgument (Transform)
What it means
The TransformedBitmap(source, transform) constructor requires both a non-null source and a non-null transform; a null transform yields no valid bitmap definition, so it throws InvalidOperationException with SR.Image_NoArgument("Transform"). The source null case is already handled by ArgumentNullException.ThrowIfNull.
Solutions
- Pass Transform.Identity instead of null when no transform is needed
- Use the source bitmap directly rather than wrapping in TransformedBitmap when no transform applies
- Coalesce the nullable transform: new TransformedBitmap(source, transform ?? Transform.Identity)
Example fix
// before Transform transform = GetOptionalTransform(); // may be null var tb = new TransformedBitmap(source, transform); // after Transform transform = GetOptionalTransform() ?? Transform.Identity; var tb = new TransformedBitmap(source, transform);
Defensive patterns
Strategy: validation
Validate before calling
if (transform == null)
throw new ArgumentException("Transform must not be null", nameof(transform)); Type guard
static bool HasTransform(Transform t) => t != null;
Try / catch
try { var tb = new TransformedBitmap(source, transform); }
catch (InvalidOperationException ex) when (ex.Message.Contains("Transform"))
{ /* supply Transform.Identity fallback */ } Prevention
- Coalesce optional transforms with ?? Transform.Identity
- Never pass raw nullable transform fields into bitmap constructors
- Prefer BeginInit/EndInit with explicit property assignment so missing parts fail clearly
When it happens
Trigger: new TransformedBitmap(source, transform) where a nullable Transform variable is null — e.g. an optional transform resolved to null, or a transform factory returned null before the constructor call.
Common situations: Optional rotation logic that skips assignment when no rotation is needed; transform created from deserialized/config data that failed to resolve; BeginInit-style code refactored into direct construction with an unset Transform property.
Related errors
- SR.Image_OnlyOrthogonal
- annotation component
- ArgumentNullException
- ArgumentNullException(argName)
- ArgumentNullException("characterBufferReference.CharacterBuf…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/cf956d4a98d016f1.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/TransformedBitmap.cs:36
/// </summary>
public TransformedBitmap()
: base(true) // Use base class virtuals
{
}
/// <summary>
/// Construct a TransformedBitmap with the given newTransform
/// </summary>
/// <param name="source">BitmapSource to apply to the newTransform to</param>
/// <param name="newTransform">Transform to apply to the bitmap</param>
public TransformedBitmap(BitmapSource source, Transform newTransform)
: base(true) // Use base class virtuals
{
ArgumentNullException.ThrowIfNull(source);
if (newTransform == null)
{
throw new InvalidOperationException(SR.Format(SR.Image_NoArgument, "Transform"));
}
if (!CheckTransform(newTransform))
{
throw new InvalidOperationException(SR.Image_OnlyOrthogonal);
}
_bitmapInit.BeginInit();
Source = source;
Transform = newTransform;
_bitmapInit.EndInit();
FinalizeCreation();
}
// ISupportInitialize
View on GitHub (pinned to 81131a70a4)