Skip to content
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

POST /security/alerts_v2/{alertId}/comments returns 400 "Empty Payload. JSON content expected." #2514

Closed
jcoliz opened this issue May 23, 2024 · 2 comments
Labels
Status: No recent activity status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close type:bug A broken experience

Comments

@jcoliz
Copy link

jcoliz commented May 23, 2024

Describe the bug

Calling the following code, where alertId is an Id known to the service, and commentText is "New comment", leads to an Microsoft.Graph.Models.ODataErrors.ODataError exception being thrown.

    protected Task<List<Microsoft.Graph.Models.Security.AlertComment>?> SetComment(string alertId, string commentText)
    {
        Microsoft.Graph.Models.Security.AlertComment comment = new() { OdataType = "microsoft.graph.security.alertComment", Comment = commentText };
        List<Microsoft.Graph.Models.Security.AlertComment> body = [ comment ];

        return graphClient.Security.Alerts_v2[alertId].Comments.PostAsync(body);
    }

App does have necessary SecurityAlert.ReadWrite.All permission for this call. Looks like an SDK issue, because no obvious reason that body would be blank. See "Other information" below for my theory on the problem.

Expected behavior

Call is expected to succeed

How to reproduce

Please see above

SDK Version

5.53.0

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output

Click to expand log Exception thrown: 'Microsoft.Graph.Models.ODataErrors.ODataError' in System.Private.CoreLib.dll

Configuration

  • OS: Windows 11 23H2
  • Arch: x64

Other information

I am wondering about this line at CommentsRequistBuilder.cs:134:

        requestInformation.SetContentFromParsable(base.RequestAdapter, "application/json", (IEnumerable<AlertComment>)body);

If I try to do this myself, I get an exception

        List<Microsoft.Graph.Models.Security.AlertComment> body = [ comment ];
        var ew = (IEnumerable<AlertComment>)body;
Unable to cast object of type 'System.Collections.Generic.List`1[Microsoft.Graph.Models.Security.AlertComment]' to type 'System.Collections.Generic.IEnumerable`1[MdeSamples.Models.AlertComment]'.

Why even make the cast? The compiler will match just fine without it.

@jcoliz jcoliz added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels May 23, 2024
@andrueastman
Copy link
Member

Thanks for raising this @jcoliz

Taking a look at the request builder below, there does not seem to be a cast bein performed by the SDK. Any chance you can confirm the location of the line you are speaking of?

requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body);

Furthermore the error seems to suggest another type that exists in your code that is not Microsoft.Graph.Models.Security.AlertComment which seems to be MdeSamples.Models.AlertComment any chance you can confirm if the issue here is not an ambiguous reference due to multiple namespaces imported that have a type called AlertComment?

@andrueastman andrueastman added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close Needs: Author Feedback and removed status:waiting-for-triage An issue that is yet to be reviewed or assigned labels May 27, 2024
Copy link
Contributor

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: No recent activity status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close type:bug A broken experience
Projects
None yet
Development

No branches or pull requests

2 participants