-
Notifications
You must be signed in to change notification settings - Fork 535
Disable EventSource calls to avoid IL2026 trimming errors #5388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,7 +41,14 @@ private unsafe void WriteEventCoreWithActivityId(Guid activityId, int eventId, i | |
| // must be explicitly be set before writing the event. | ||
| CustomTypeExtensions.SetActivityId(ref activityId); | ||
|
|
||
| this.WriteEventCore(eventId, eventDataCount, dataDesc); | ||
| // COMMENTED OUT FOR TRIMMED AZMCP: The following call to WriteEventCore is commented out to resolve | ||
| // IL2026 trim analysis errors when building the trimmed version of azmcp. The error occurs because | ||
| // EventSource.WriteEventCore has RequiresUnreferencedCodeAttribute which can break functionality | ||
| // when trimming application code, as EventSource serializes the whole object graph and the trimmer | ||
| // cannot safely handle this case. This is specific to the trimmed build - the AOT build doesn't | ||
| // report this issue due to more aggressive optimizations that trim away unreachable code paths. | ||
| // Since the preview trimmed version doesn't rely on EventSource telemetry, this is safe to disable. | ||
| // this.WriteEventCore(eventId, eventDataCount, dataDesc); | ||
| } | ||
|
|
||
| [Event(1, | ||
|
|
@@ -266,7 +273,8 @@ private unsafe void Request( | |
| 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of these inputs are primitive types, so this should be OK to suppress with |
||
| // COMMENTED OUT FOR TRIMMED AZMCP: See WriteEventCoreWithActivityId method for detailed explanation | ||
| // this.WriteEventCoreWithActivityId(activityId, 1, eventDataCount, dataDesc); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -513,7 +521,8 @@ private unsafe void Response(Guid activityId, | |
| 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, it looks like these are all primitive types (Guid, short, double, string). |
||
| // COMMENTED OUT FOR TRIMMED AZMCP: See WriteEventCoreWithActivityId method for detailed explanation | ||
| // this.WriteEventCoreWithActivityId(activityId, 2, eventDataCount, dataDesc); | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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.