2016-01-20 18 views
3

無論我試圖我無法設置一個用戶對象上的擴展屬性,這裏是可再現的一段代碼:根據提琴手天青架構擴展在圖形客戶端

public async Task CleanTest(string extName) 
     { 
     ExtensionProperty ep = new ExtensionProperty 
     { 
      Name = extName, 
      DataType = "String", 
      TargetObjects = { "User" } 
     }; 

     App app = (App)(await _client.Applications.Where(a => a.AppId == _managementAppClientId).ExecuteSingleAsync()); 
     app.ExtensionProperties.Add(ep); 
     await app.UpdateAsync(); 

     GraphUser user = (GraphUser)(await _client.Users.Where(u => u.UserPrincipalName.Equals("email")).ExecuteSingleAsync()); 
     string propName = FormatExtensionPropertyName(extName); //formats properly as extesion_xxx_name 
     user.SetExtendedProperty(propName, "testvalue"); 
     //user.SetExtendedProperty(extName, "testvalue"); 
     await user.UpdateAsync(); // fails here 
     } 

user.UpdateAsync()不連走出去和應用失敗的異常:

「屬性‘extension_e206e28ff36244b19bc56c01160b9cf0_UserEEEqdbtgd3ixx2’上鍵入‘Microsoft.Azure.ActiveDirectory.GraphClient.Internal.User’不存在,請確保只使用由定義的屬性名稱。類型。」

回答

1

萬一你還在尋找解決這個問題或其他人也面臨同樣的問題:

我得到了類似的問題,看起來,至少對我來說,問題是在最新版的「 Microsoft.Data.Services.Client「包 - 5.7.0(或其中的一個依賴項)。當我降級到以前的版本時 - 5.6.4它起到了魅力的作用。

我有同樣的症狀 - 擴展屬性的更新是失敗甚至W/O任何請求時(也用小提琴手)

希望它能幫助!

阿爾喬姆李曼

+0

太好了,我今天來試試吧。微軟是否意識到這個問題? ) –

+0

好像其他人正在追蹤這個問題[這裏](https://github.com/Azure-Samples/active-directory-dotnet-graphapi-console/issues/28)。 –

2

這個問題也正在這裏追蹤: https://github.com/Azure-Samples/active-directory-dotnet-graphapi-console/issues/28

我已經得到了這個bug的替代的解決方法,對於那些希望使用5.7版本的OData庫,而不是重定向到v5.6.4版本。

添加請求管道配置處理程序。

// initialize in the usual way 
ActiveDirectoryClient activeDirectoryClient = 
    AuthenticationHelper.GetActiveDirectoryClientAsApplication(); 
// after initialization add a handler to the request pipline configuration. 
activeDirectoryClient.Context 
    .Configurations.RequestPipeline 
    .OnMessageWriterSettingsCreated(UndeclaredPropertyHandler); 

在處理程序,更改作家設置SupportUndeclaredValueProperty的ODataUndeclaredPropertyBehaviorKinds值。

private static void UndeclaredPropertyHandler(MessageWriterSettingsArgs args) 
{ 
    var field = args.Settings.GetType().GetField("settings", 
    BindingFlags.NonPublic | BindingFlags.Instance); 
    var settingsObject = field?.GetValue(args.Settings); 
    var settings = settingsObject as ODataMessageWriterSettings; 
    if (settings != null) 
    { 
    settings.UndeclaredPropertyBehaviorKinds = 
     ODataUndeclaredPropertyBehaviorKinds.SupportUndeclaredValueProperty; 
    } 
} 
+0

儘管有用,但這更多的是評論而不是答案。 –