dotnet/wpf · error · ArgumentNullException
The exception argument cannot be null.
Error message
The exception argument cannot be null.
What it means
The PropertyMappingExceptionEventArgs constructor validates its arguments up front: the exception to report must be non-null because the event args exist solely to carry a mapping failure. Passing null throws ArgumentNullException naming 'exception'.
Solutions
- Pass the actual caught Exception instance into the constructor.
- Guard before constructing: if (ex != null) new PropertyMappingExceptionEventArgs(ex, prop, value);
- Remove code paths that synthesize event args without a real exception.
Example fix
// before
new PropertyMappingExceptionEventArgs(lastError, "Background", value); // lastError may be null
// after
if (lastError != null)
new PropertyMappingExceptionEventArgs(lastError, "Background", value); Defensive patterns
Strategy: validation
Validate before calling
if (ex == null) throw new InvalidOperationException("Cannot report a mapping error without an exception");
var args = new PropertyMappingExceptionEventArgs(ex, propertyName, value); Type guard
bool CanBuildMappingEventArgs(Exception ex, string prop) => ex != null && !string.IsNullOrEmpty(prop);
Try / catch
try { var e = new PropertyMappingExceptionEventArgs(ex, prop, value); }
catch (ArgumentNullException) { log.Error("No exception captured to report"); } Prevention
- Never build event args from a nullable exception field without a null check
- Capture the exception inside the catch block and forward it immediately
- In tests, always pass a concrete exception instance (e.g. new InvalidOperationException())
When it happens
Trigger: Constructing PropertyMappingExceptionEventArgs(null, "someProp", value) inside a PropertyMappingError handler or test that builds the event args manually; catching and forwarding an exception variable that turned out to be null.
Common situations: Unit tests simulating mapping errors; wrapper code that stores the last exception in a field initialized to null and then builds event args from it.
Related errors
- Argument 'propertyName' cannot be null or empty.
- ArgumentNullException(nameof(assemblyNames))
- nameof(name)
- SR.EventArgIsNull
- anchorLocator.Parts
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/b1dff31bea8bc0a7.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WindowsFormsIntegration/System/Windows/Integration/PropertyMappingExceptionEventArgs.cs:24
namespace System.Windows.Forms.Integration
{
/// <summary>
/// Enables the user to see the property that threw an exception, and to preview or cancel the exception.
/// </summary>
public class PropertyMappingExceptionEventArgs : IntegrationExceptionEventArgs
{
private string _propertyName;
private object _propertyValue;
/// <summary>
/// Initializes a new instance of the PropertyMappingExceptionEventArgs class.
/// </summary>
public PropertyMappingExceptionEventArgs(Exception exception, string propertyName, object propertyValue)
: base(false, exception)
{
if (exception == null)
{
throw new ArgumentNullException(string.Format(CultureInfo.CurrentCulture, SR.WFI_NullArgument, "exception"));
}
if (string.IsNullOrEmpty(propertyName))
{
throw new ArgumentNullException(string.Format(CultureInfo.CurrentCulture, SR.WFI_ArgumentNullOrEmpty, "propertyName"));
}
_propertyName = propertyName;
_propertyValue = propertyValue;
}
/// <summary>
/// Identifies the property that was being mapped when the exception occurred.
/// </summary>
public string PropertyName
{
get
{
return _propertyName;
}View on GitHub (pinned to 81131a70a4)