microsoftgraph / microsoftgraph/msgraph-sdk-dotnet

Attaching ItemAttachment using SDK

Open
#2,872 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type:bug
Dominant language
C#
Stars
789
Forks
264
Avg merge
15h 17m
Merged PRs (30d)
3

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with AttachmentsRequestBuilder.PostAsync and the ItemAttachment example in the report, using SDK version 5.68.0. Reproduce the abstract outlookItem error and the five-header error while reviewing workaround #2334 and the described backing-store and header changes. Done means identifying a supported way to send a forwarded message with an item attachment.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.