Skip to content

Invalid use of Unsafe.As in System.Diagnostics.DiagnosticSource #40366

@jkotas

Description

@jkotas

get => _tags?.Enumerate() ?? Unsafe.As<IEnumerable<KeyValuePair<string, object?>>>(s_emptyBaggageTags);
is invalid use of Unsafe.As.

Unsafe.As cannot be used to cast object to a type that it is not assignable to and then hand the reference of invalid type out.

Please do not use Unsafe.As unless it is really required. Having an extra static field of the right type is both more correct and also likely cheaper than Unsafe.As.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions