Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6947,15 +6947,7 @@ internal static DynamicMetaObject InvokeDotNetMethod(
// - Log method invocation to AMSI Notifications (can throw PSSecurityException)
// - Invoke method
string targetName = methodInfo.ReflectedType?.FullName ?? string.Empty;
expr = Expression.Block(
Expression.Call(
CachedReflectionInfo.MemberInvocationLoggingOps_LogMemberInvocation,
Expression.Constant(targetName),
Expression.Constant(name),
Expression.NewArrayInit(
typeof(object),
args.Select(static e => e.Expression.Cast(typeof(object))))),
expr);
MaybeAddMemberInvocationLogging(expr, targetName, name, args);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be missing something, but it looks like the return value from this method call is never used; shouldn't that be expr = MaybeAddMemberInvocationLogging(expr, targetName, name, args);?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good pickup, sorry for missing that. @SeeminglyScience will be submitting a new PR to fix that.

@iSazonov iSazonov Dec 10, 2024

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That says there are no tests.
And many would say thank you for such an omission 😄


// If we're calling SteppablePipeline.{Begin|Process|End}, we don't want
// to wrap exceptions - this is very much a special case to help error
Expand Down Expand Up @@ -7566,6 +7558,33 @@ internal static void InvalidateCache()
}
}

#nullable enable
private static Expression MaybeAddMemberInvocationLogging(
Expression expr,
string targetName,
string name,
DynamicMetaObject[] args)
{
#if UNIX && !DEBUG
// For efficiency this is a no-op on non-Windows platforms in release builds.
return expr;
#else
Expression[] invocationArgs = new Expression[args.Length];
for (int i = 0; i < args.Length; i++)
{
invocationArgs[i] = args[i].Expression.Cast(typeof(object));
}
return Expression.Block(
Expression.Call(
CachedReflectionInfo.MemberInvocationLoggingOps_LogMemberInvocation,
Expression.Constant(targetName),
Expression.Constant(name),
Expression.NewArrayInit(typeof(object), invocationArgs)),
expr);
#endif
}
#nullable disable

#endregion
}

Expand Down