1

我得到以下錯誤:VB.NET - 錯誤參考到非共享成員需要的對象引用(WindowsIdentity.Groups性)

Error 1 Reference to a non-shared member requires an object reference. 
       (on WindowsIdentity.Groups) 

這是我的代碼從使用WindowsIdentity.Groups property顯示當前用戶所屬組的標識引用。此代碼是爲WindowsIdentity class提供的更大示例的一部分。

Public ReadOnly Property Groups As IdentityReferenceCollection 
    Get 
     Dim irc As IdentityReferenceCollection 
     Dim ir As IdentityReference 

     irc = WindowsIdentity.Groups 
     For Each ir In irc 
      MsgBox(ir.Value) 
     Next 

    End Get 
    End Property 

我試圖把修復這個錯誤:

Dim myWindowsIdentity As New WindowsIdentity 

而且得到了以下錯誤:

Error 2 Overload resolution failed because no accessible 'New' accepts 
       this number of arguments. 

回答

1

你必須擁有的對象,或者您必須創建一個新的(你做的)。第二個錯誤是因爲你沒有爲構造函數提供任何參數(新建)。如果你使用Visual Studio,它應該有智能感知。把一個(作爲「新的WindowsIdentity」之後,並檢查,看看有什麼論據是必需的。

+0

我不知道該放什麼,有7個選項提供的intellisense – 2011-04-27 17:06:34

+0

提供它的參數最符合什麼目的你正在嘗試執行,如果你不知道,谷歌的對象 – FreeSnow 2011-04-27 17:10:05

+0

Uhhhhh「谷歌它」不是一個有用的答案哈哈。任何其他建議? – 2011-04-28 15:57:36

相關問題