Disable EventSource calls to avoid IL2026 trimming errors#5388
Disable EventSource calls to avoid IL2026 trimming errors#5388anuchandy wants to merge 1 commit intoAzure:msdata/aotfrom
Conversation
| // must be explicitly be set before writing the event. | ||
| CustomTypeExtensions.SetActivityId(ref activityId); | ||
|
|
||
| this.WriteEventCore(eventId, eventDataCount, dataDesc); |
There was a problem hiding this comment.
This works, but I think what you should do is add RequiresUnreferencedCode to this method, then look at the callers. That is, WriteEventCore is annotated with
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource will serialize the whole object graph. Trimmer will not safely handle this case because properties may be trimmed. This can be suppressed if the object is a primitive type")]
I think the same thing applies here. The responsibility is on the callers to ensure that they're either not calling this in any trim-compatible code path, or they are correctly suppressing the warning because they're only serializing primitive types.
| dataDesc[32].DataPointer = (IntPtr)(fixedXDate); | ||
| dataDesc[32].Size = (xDate.Length + 1) * UnicodeEncodingCharSize; | ||
|
|
||
| this.WriteEventCoreWithActivityId(activityId, 1, eventDataCount, dataDesc); |
There was a problem hiding this comment.
All of these inputs are primitive types, so this should be OK to suppress with UnconditionalSuppressMessage on the parent method.
| dataDesc[29].DataPointer = (IntPtr)(fixedVersion); | ||
| dataDesc[29].Size = (version.Length + 1) * UnicodeEncodingCharSize; | ||
|
|
||
| this.WriteEventCoreWithActivityId(activityId, 2, eventDataCount, dataDesc); |
There was a problem hiding this comment.
Same here, it looks like these are all primitive types (Guid, short, double, string).
|
What concerns me here is that this should be generating warnings before you ever get to MCP. Is this project annotated with |
|
Ah, I see the problem -- this project only builds for netstandard2.0. I will try to add a net8.0 target. |
|
closing this based on the offline discussion with Andy, he is working on a pr to address this by adding annotations |
Same idea as Azure#5388, but this provides appropriate attributes to mark the use as safe. The long-term goal here should be to add a net8 target to validate that this is correct.
Same idea as #5388, but this provides appropriate attributes to mark the use as safe. The long-term goal here should be to add a net8 target to validate that this is correct.
[Internal] Telemetry : Disable EventSource calls to avoid IL2026 trimming errors
Description
Comment out EventSource calls to resolve IL2026 trimming errors
IL2026 trim analysis errors when building trimmed applications
breaks functionality during trimming as it serializes the whole object graph
optimization levels
Description
Please include a summary of the change and which issue is fixed. Include samples if adding new API, and include relevant motivation and context. List any dependencies that are required for this change.
Type of change
Please delete options that are not relevant.
Closing issues
To automatically close an issue: closes #IssueNumber