microsoftgraph / msgraph-beta-sdk-dotnet

The Microsoft Graph Client Beta Library for .NET supports the Microsoft Graph /beta endpoint. (preview)
Other
97 stars 32 forks source link

"Parameter count mismatch" when trying to update Application in AAD B2C #426

Closed ArveSystad closed 2 years ago

ArveSystad commented 2 years ago

Reproduced by:

var apps = await _graphClient.Applications.GetAsync();
var application = apps.Value.FirstOrDefault(x => x.DisplayName == "MyApp");
await _graphClient.Applications[application.Id].PatchAsync(application);

I have an existing application in Azure AD B2C, and trying to set some properties. Always throws up "Parameter count mismatch", even when not modifying the application at all, like shown above.

(Obviosuly, in my real code, I do modify the object, but regardless of what I do I get the same. In my specific case, I'm trying to add RedirectUris on the Application when it fails. I do use PatchAsync with success on API connectors in the same little app.)

Parameter count mismatch.
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
   at Microsoft.Kiota.Serialization.Json.JsonSerializationWriter.WriteNonParsableObjectValue[T](String key, T value)
   at Microsoft.Kiota.Serialization.Json.JsonSerializationWriter.WriteAnyValue[T](String key, T value)
   at Microsoft.Kiota.Serialization.Json.JsonSerializationWriter.WriteAdditionalData(IDictionary`2 value)
   at Microsoft.Graph.Beta.Models.Entity.Serialize(ISerializationWriter writer)
   at Microsoft.Graph.Beta.Models.DirectoryObject.Serialize(ISerializationWriter writer)
   at Microsoft.Graph.Beta.Models.Application.Serialize(ISerializationWriter writer)
   at Microsoft.Kiota.Serialization.Json.JsonSerializationWriter.WriteObjectValue[T](String key, T value)
   at Microsoft.Kiota.Abstractions.RequestInformation.SetContentFromParsable[T](IRequestAdapter requestAdapter, String contentType, T[] items)
   at Microsoft.Graph.Beta.Applications.Item.ApplicationItemRequestBuilder.CreatePatchRequestInformation(Application body, Action`1 headers, IEnumerable`1 options)
   at Microsoft.Graph.Beta.Applications.Item.ApplicationItemRequestBuilder.PatchAsync(Application body, Action`1 headers, IEnumerable`1 options, IResponseHandler
responseHandler, CancellationToken cancellationToken)
(....my own application code stack trace continues here...)

Tried using the non-beta SDK, but that doesn't seem to let me add B2C User Flows, so for now, that doesn't fit my use case elsewhere.

If I add them manually through the portal, they show up when using this SDK.

As a side note: I also notice when trying to add them via Terraform (web.redirecturis), nothing shows up anywhere (neither portal nor SDK). Possibly related?

andrueastman commented 2 years ago

Hey @ArveSystad,

Thanks for raising this. Any chance you could share the version of the SDK you are using when making the request?

andrueastman commented 2 years ago

Hey @ArveSystad,

This looks to be an issue with the serialization library. I have created https://github.com/microsoft/kiota-serialization-json-dotnet/pull/8 to fix this. You should be able to pull the updated package in the next day or so.

In the meantime, if you are not modifying any values in the additionalData you can probably work around the issue excluding values in the additionalData if you did not modify them by doing something like this.

var apps = await graphServiceClient.Applications.GetAsync();
var application = apps.Value.FirstOrDefault(x => x.DisplayName == "MyApp");
application.AdditionalData = new Dictionary<string, object>(); // exclude/reset values in additionData for now if we didn't modify them.
await _graphClient.Applications[application.Id].PatchAsync(application);
ArveSystad commented 2 years ago

Brilliant, thanks! I guess I'm a bit late to the party with the version, but for whatever it's worth: <PackageReference Include="Microsoft.Graph.Beta" Version="5.1.0-preview" />.