unoplatform/uno · error · ArgumentNullException

instance

Error message

instance

What it means

Thrown by the XamlObjectEventArgs constructor when the instance argument is null. XamlObjectEventArgs carries a reference to an object being processed during XAML object reading/writing; a null instance has no type identity to report, so the constructor rejects it.

Source

Thrown at src/SourceGenerators/System.Xaml/System.Xaml/XamlObjectEventArgs.cs:36

// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Windows.Markup;

namespace Uno.Xaml
{
	public class XamlObjectEventArgs : EventArgs
	{
		public XamlObjectEventArgs (object instance)
		{
			if (instance == null)
				throw new ArgumentNullException ("instance");
			Instance = instance;
		}

		public object Instance { get; private set; }
	}
}

View on GitHub (pinned to 0418340488)

Solutions

  1. Guard for null before constructing XamlObjectEventArgs: if (instance != null) args = new XamlObjectEventArgs(instance);
  2. Fix upstream code so the object passed to the event is never null (ensure object construction succeeded).
  3. Skip the event raise entirely when the instance is null.

Example fix

// before
var args = new XamlObjectEventArgs(currentObject);
// currentObject is null → throws

// after
if (currentObject != null)
{
    var args = new XamlObjectEventArgs(currentObject);
    handler?.Invoke(this, args);
}
Defensive patterns

Strategy: validation

Validate before calling

if (instance == null) return;
var args = new XamlObjectEventArgs(instance);

Try / catch

try { var args = new XamlObjectEventArgs(instance); handler?.Invoke(this, args); }
catch (ArgumentNullException) { /* skip event for null instance */ }

Prevention

When it happens

Trigger: Constructing new XamlObjectEventArgs(null). This fires from event-handler invocation code or custom XAML object reader hooks that pass a potentially-null object.

Common situations: Subscribing to XamlObjectReader or XamlXmlReader events (e.g. value-set callbacks) and constructing XamlObjectEventArgs from data that may be null. Custom XAML reader implementations that fire object events with unguarded null values.

Related errors


AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13). Data as JSON: /api/errors/095993ebdc39dc54. Report an issue: GitHub.