Question

I am getting the following error:

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

Here's my code from that uses the WindowsIdentity.Groups property to display the identity references for the groups the current user belongs to. This code is part of a larger example provided for the 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

I tried fixing this error by putting:

    Dim myWindowsIdentity As New WindowsIdentity

but got the following error:

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

Solution

You must either have the object, or you must create a new one (which you did). The second error is because you haven't provided any arguments for the constructors (new). If you are using Visual Studio, it should have intellisense. Put a ( after "as new WindowsIdentity" and check to see what arguments are required.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top