1

次のエラーが発生します。

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

これは、 WindowsIdentity.Groupsプロパティを使用して、現在のユーザーが属するグループのID参照を表示するコードです。このコードは、WindowsIdentityクラスに提供されているより大きな例の一部です。

    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.   
4

1 に答える 1

1

オブジェクトを持っているか、新しいオブジェクトを作成する必要があります (作成しました)。2 番目のエラーは、コンストラクター (新規) に引数を指定していないためです。Visual Studio を使用している場合は、IntelliSense が必要です。"as new WindowsIdentity" の後に ( を入力し、必要な引数を確認します。

于 2011-04-27T16:26:24.777 に答える