Skip to content

Re-evaluate the nullabilty of eventName parameters in EventSourceActivity #35157

@bartonjs

Description

@bartonjs

The public methods on this internal type have xmldoc that says that eventName can be null.

/// <summary>
/// Writes an event associated with this activity.
/// May only be called when the activity is in the Started state.
/// </summary>
/// <param name="eventName">
/// The name to use for the event. If null, the name is determined from
/// data's type.
/// </param>
/// <param name="data">The data to include in the event.</param>
public void Write<T>(string? eventName, T data)
{
EventSourceOptions options = default;
this.Write(this.eventSource, eventName, ref options, ref data);
}

But one of the two ArgumentNullException sources in this class is for when eventName is null:

private void Write<T>(EventSource eventSource, string? eventName, ref EventSourceOptions options, ref T data)
{
if (this.state != State.Started)
throw new InvalidOperationException(); // Write after stop.
if (eventName == null)
throw new ArgumentNullException();
eventSource.Write(eventName, ref options, ref this.activityId, ref s_empty, ref data);
}

maybe there's something I'm missing, though. Spotted in a code review for updating parameter names for ArgumentException types.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions