Skip to content

Attaching ItemAttachment using SDK #2872

@bynnoh

Description

@bynnoh

Describe the bug

What I'm trying to do:
Forward a message with modifications using the SDK.

The issue I'm facing:
The item attachment in the forwarded message is not being attached properly using the SDK.

I've tried following:

if (attachment is ItemAttachment itemAttachment && itemAttachment.Item is Message message)
{
  return new ItemAttachment
  {
    Name = itemAttachment.Name,
    Item = message
  };
}

await graphClient.Users[mailAddress].Messages[messageId].Attachments.PostAsync(returnedItemAttachment);

Initially, I encountered the error:
"Cannot process input of abstract type 'microsoft.graph.outlookItem'."

After finding #2334 , I applied message.BackingStore.InitializationCompleted = false;.

However, this led to another error:
"Maximum number of headers in one message should be less than or equal to 5."

To resolve this, I cleared both message.InternetMessageHeaders and BackingStore, but this brought back the first error.

Question:
How can I properly add an item attachment?

I also attempted to create a new Message object from the existing Item, but this approach doesn’t seem ideal due to potential deserialization errors when handling nested attachments.

Expected behavior

Message sent with attached item attachment.

How to reproduce

Described above.

SDK Version

5.68.0

Latest version known to work for scenario above?

No response

Known Workarounds

#2334

Debug output

Click to expand log
Microsoft.Graph.Models.ODataErrors.ODataError: Cannot process input of abstract type 'microsoft.graph.outlookItem'
   at
Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.ThrowIfFailedResponseAsync(HttpResponseMessage response, Dictionary2 errorMapping, Activity activityForAttributes, CancellationToken cancellationToken)
   at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.SendAsync[ModelType](RequestInformation requestInfo, ParsableFactory1 factory, Dictionary2 errorMapping, CancellationToken cancellationToken)
   at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.SendAsync[ModelType](RequestInformation requestInfo, ParsableFactory1 factory, Dictionary2 errorMapping, CancellationToken cancellationToken)
   at Microsoft.Graph.Users.Item.Messages.Item.Attachments.AttachmentsRequestBuilder.PostAsync(Attachment body, Action1 requestConfiguration, CancellationToken cancellationToken);
ry.HttpClientRequestAdapter.SendAsync[ModelType](RequestInformation requestInfo, ParsableFactory1 factory, Dictionary2 errorMapping, CancellationToken cancellationToken)
   at Microsoft.Graph.Users.Item.Messages.Item.Attachments.AttachmentsRequestBuilder.PostAsync(Attachment body, Action1 requestConfiguration, CancellationToken cancellationToken);

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:bugA broken experience

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions