Reputation: 553
When trying to load the members of a group using the Microsoft.Graph Client Library that has a contact as a member (besides regular users), the following Exception is thrown:
The value 'Microsoft.Graph.Contact' is not of type 'Microsoft.Graph.DirectoryObject' and cannot be used in this generic collection. Parameter name: value at Newtonsoft.Json.Utilities.CollectionWrapper\`1.VerifyValueType(Object value) at Newtonsoft.Json.Utilities.CollectionWrapper\`1.System.Collections.IList.Add(Object value) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Populate(JsonReader reader, Object target) at Newtonsoft.Json.Serialization.JsonSerializerProxy.PopulateInternal(JsonReader reader, Object target) at Newtonsoft.Json.Converters.CustomCreationConverter\`1.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings) at Microsoft.Graph.Serializer.DeserializeObject[T](String inputString) at Microsoft.Graph.BaseRequest.d__27`1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Graph.GroupMembersCollectionWithReferencesRequest.d__2.MoveNext()
Code that throws the exception
var grpMembers = client.Groups["Id of a group with a contact as member"].Members.Request().GetAsync().Result;
When using the online graph-explorer, the request returns the contact just fine. I understand, that contacts are not supported in v1.0 of Microsoft.Graph. So is there a way of using a filter clause to limit the returned members to the supported types?
Upvotes: 3
Views: 660
Reputation: 5838
Thanks for reporting this. I'll create a bug for this and we'll take a look. We also have a backlog item to allow casting so that the response only contains the object types you need. We'd need to support this in the client library too I expect. However, in this case it looks like this might be a service bug since v1.0 should not even "know" about org contacts, and at first glance it looks like this is being mapped to a personal contact.
We'll get back to you on this shortly. Again, thanks for reporting.
Upvotes: 3