在Microsoft.Graph Client中查询组成员时出现异常

时间:2016-04-20 07:49:43

标签: c# azure office365 azure-active-directory microsoft-graph

尝试使用具有联系人作为成员的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()

抛出异常的代码

<?php
$ini = parse_ini_file("data.ini.php");
$host_rfe    = $ini["host_rfe"];
$host_nav    = $ini["host_nav"];
$rfedatabase = $ini["rfedatabase"];
$navdatabase = $ini["navdatabase"];
$login_db_rfe    = $ini["login_db_rfe"];
$pass_db_rfe     = $ini["pass_db_rfe"];
$login_db_nav    = $ini["login_db_nav"];
$pass_db_nav     = $ini["pass_db_nav"];
$port        = $ini["port"];

// Connecting to Database
if(!($sqlconn=@mysql_connect("$host_rfe:$port",$login_db_rfe,$pass_db_rfe))) {
    echo "<p align=\"center\"><big><img src=\"images/redx.png\"><br/><strong>It wasn't possible to connect to MySQL server. Please, check the configurations.</strong></big></p>";
    exit;
}

// Select Database
if(!($con=@mysql_select_db($rfedatabase,$sqlconn))) {
    echo "<p align=\"center\"><big><img src=\"images/redx.png\"><br/><strong>It wasn't possible to connect to database <i>$rfedatabase</i>. Please, check the configurations.</strong></big></p>";
    exit;
}

/*========================================================================
 Function: change_db
    Usage: This function changes the pointer to another MySQL Database
Arguments:
    $sqlconn - Connection pointer
    $db      - Destnation's database
========================================================================*/
function change_db($sqlconn,$db) {

    global $sqlconn;

    if(!($con=mysql_select_db($db,$sqlconn))) {
        echo "<p align=\"center\"><big><img src=\"images/redx.png\"><br/><strong>It wasn't possible to connect to database <i>$db</i>. Please, check the configurations.</strong></big></p>";
        exit;
    }

    return $con;
}
?>

使用在线graph-explorer时,请求会很好地返回联系人。据我所知,Microsoft.Graph的v1.0不支持联系人。那么有没有办法使用filter子句将返回的成员限制为支持的类型?

1 个答案:

答案 0 :(得分:3)

感谢您报告此事。我将为此创建一个错误,我们将看一看。我们还有一个积压项目允许转换,以便响应只包含您需要的对象类型。我们也希望在客户端库中支持这一点。但是,在这种情况下,看起来这可能是一个服务错误,因为v1.0甚至不应该“知道”关于组织联系人,乍一看它看起来像是映射到个人联系人。

我们很快就会回复你。再次感谢报道。