microsoftgraph / msgraph-sdk-dotnet

Microsoft Graph Client Library for .NET!
https://graph.microsoft.com
Other
672 stars 242 forks source link

Cannot process input of abstract type 'microsoft.graph.extension' #2516

Open vknht opened 1 month ago

vknht commented 1 month ago

Describe the bug

Hello,

I am trying to load an Extension for a Contact, Change a Value then save it, but i am getting the Error in the title. I found this (https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/1723) issue before, but there, a contact is loaded and then the Extension is changed. In my case, i am loading the Extension and nothing else.

Expected behavior

not getting an error i guess?

How to reproduce

var extension = (await _graphClient.Me.ContactFolders["MyContactFolderId"].Contacts["MyContactId"].Extensions["MyExtension"].GetAsync()) as OpenTypeExtension; extension.AdditionalData["MyProperty"] = "MyNewValue"; await _graphClient.Me.ContactFolders["MyContactFolderId"].Contacts["MyContactId"].Extensions["MyExtension"].PatchAsync(extension);

SDK Version

5.54.0

Latest version known to work for scenario above?

Unknown

Known Workarounds

None

Debug output

Click to expand log ``` ```

Configuration

Other information

No response

andrueastman commented 1 month ago

Thanks for raising this @vknht

Any chance you get a different result if you do something like this?

            var extension = new OpenTypeExtension();
            extension.AdditionalData["MyProperty"] = "MyNewValue";
            await graphClient.Me.ContactFolders["MyContactFolderId"].Contacts["MyContactId"].Extensions["MyExtension"].PatchAsync(extension);
vknht commented 1 month ago

Hi,

this is interesting. If I do something like this:

var extension = (await _graphClient.Me.ContactFolders["MyContactFolderId"].Contacts["MyContactId"].Extensions["MyExtension"].GetAsync()) as OpenTypeExtension;
extension.AdditionalData["MyProperty"] = "MyNewValue";

var extension02 = new OpenTypeExtension()
{
  Id = extension.Id,
  AdditionalData = extension.AdditionalData,
  ExtensionName = extension.ExtensionName,
  OdataType = extension.OdataType,
};

await graphClient.Me.ContactFolders["MyContactFolderId"].Contacts["MyContactId"].Extensions["MyExtension"].PatchAsync(extension02);

it works. "OdataType" is the same on both instances: "#microsoft.graph.openTypeExtension"

Is there a better way of doing this instead of mapping everything into a new instance?

vknht commented 1 month ago

anything new?

andrueastman commented 1 month ago

I believe the behaviour you're seeing is due to the backingStore. You can therefore probably use this instead to ensure the entire payload is serialized.


            var extension = await graphClient.Me.ContactFolders["MyContactFolderId"].Contacts["MyContactId"].Extensions["MyExtension"].GetAsync();
            extension.AdditionalData["MyProperty"] = "MyNewValue";

            // reset the backing store to force the client to send the full object
            extension.BackingStore.InitializationCompleted = false;

            await graphClient.Me.ContactFolders["MyContactFolderId"].Contacts["MyContactId"].Extensions["MyExtension"].PatchAsync(extension);
vknht commented 1 month ago

hi,

i just tried the

extension.BackingStore.InitializationCompleted = false;

and it worked.

This is much better than creating a new instance and assigning the values. Will this "fix" be implemented in a future version?

Thank you very much so far.