当尝试使用 Microsoft.Graph Client Library 加载组成员时拥有联系人作为成员(除了普通用户)时,会引发以下异常:
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;
使用在线时graph-explorer ,请求返回联系人就好了。据我了解,Microsoft.Graph v1.0 不支持联系人。那么有没有办法使用过滤子句将返回的成员限制为支持的类型?
最佳答案
感谢您报告此事。我将为此创建一个错误,我们会看一下。我们还有一个积压项目允许强制转换,以便响应仅包含您需要的对象类型。我希望我们也需要在客户端库中支持这一点。然而,在这种情况下,这看起来可能是一个服务错误,因为 v1.0 甚至不应该“知道”组织联系人,乍一看,这似乎被映射到个人联系人。
我们很快就会回复您。再次感谢您的报告。
关于c# - 在 Microsoft.Graph 客户端中查询组成员时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36737182/