microsoft / PowerPlatform-DataverseServiceClient

Code Replica for Microsoft.PowerPlatform.Dataverse.Client and supporting nuget packages.
MIT License
281 stars 51 forks source link

Microsoft.OData.ODataException: Does not support untyped value in non-open type. #290

Closed bassetassen closed 10 months ago

bassetassen commented 2 years ago

Hi, We are getting the following error when creating a custom activity record. We are using Microsoft.PowerPlatform.Dataverse.Client version 1.0.1. This is a .Net 6.0 application. I have created a small console app to reproduce the error.

var client = new ServiceClient(connectionString);

var from = new Entity("activityparty");
from["partyid"] = new EntityReference("contact", new Guid("91804760-2c9a-ec11-b400-000d3aa816e5"));

var to = new Entity("activityparty");
to["partyid"] = new EntityReference("systemuser", new Guid("f8e262c2-dd1a-ec11-b6e6-6045bd8b2013"));

var dialog = new Entity("djt_webdialog");
dialog["subject"] = "Console dialog";
dialog["description"] = "Tester en melding fra console";
dialog["regardingobjectid"] = new EntityReference("incident", new Guid("23dc120e-222c-ec11-b6e5-6045bd877eda"));
dialog["from"] = new EntityCollection(new[] { from });
dialog["to"] = new EntityCollection(new[] { to });

client.Create(dialog);

Full error message:

Microsoft.PowerPlatform.Dataverse.Client.Utils.DataverseOperationException
  HResult=0x80131500
  Message=An error occurred while validating input parameters: Microsoft.Crm.CrmException: Invalid property 'djt_webdialog_activity_parties' was found in entity 'Microsoft.Dynamics.CRM.djt_webdialog'. ---> Microsoft.OData.ODataException: Does not support untyped value in non-open type.
  Source=Microsoft.PowerPlatform.Dataverse.Client
  StackTrace:
   at Microsoft.PowerPlatform.Dataverse.Client.ServiceClient.Create(Entity entity)
   at Program.<Main>$(String[] args) in C:\xxx\Program.cs:line 21

  This exception was originally thrown at this call stack:
    [External Code]

Inner Exception 1:
HttpOperationException: Operation returned an invalid status code 'BadRequest'

I have also re-created the same example with full framework and used the CrmServiceClient from Microsoft.CrmSdk.XrmTooling.CoreAssembly and then the same code is working.

Full framework working example:

var client = new CrmServiceClient(connectionString);

var from = new Entity("activityparty");
from["partyid"] = new EntityReference("contact", new Guid("91804760-2c9a-ec11-b400-000d3aa816e5"));

var to = new Entity("activityparty");
to["partyid"] = new EntityReference("systemuser", new Guid("f8e262c2-dd1a-ec11-b6e6-6045bd8b2013"));

var dialog = new Entity("djt_webdialog");
dialog["subject"] = "Console dialog";
dialog["description"] = "Tester en melding fra console";
dialog["regardingobjectid"] = new EntityReference("incident", new Guid("23dc120e-222c-ec11-b6e5-6045bd877eda"));
dialog["from"] = new EntityCollection(new[] { from });
dialog["to"] = new EntityCollection(new[] { to });

client.Create(dialog);
MattB-msft commented 2 years ago

Thanks for your report, we will have a look... for the moment, Please set client.UseWebAPI=false after you create the client. that should clear the problem for you

bassetassen commented 2 years ago

Thank you for the fast reply, it worked with usewebapi=false :)

MattB-msft commented 10 months ago

Closing this one up.. We have altered the way this works in the DVSC and folks should not hit this code path normally.