Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0BC30469: Reference to a non-shared member requires an object referenceBC30469: Reference to a non-shared member requires an object reference
Previous
 
Next
New Post
8/14/2008 4:19 PM
 

When you call GetRoleByName, it is returning a RoleInfo object.  If that role doesn't exist, the RoleInfo object will be Nothing.  So, before you ask for its RoleID, make sure it isn't Nothing.

Dim role as RoleInfo = objRoleController.GetRoleByName(RoleName)
if role IsNot Nothing then
...
else
'create role
end if

DotNetNuke.Security.Roles.RoleController().GetUsersByRoleName() seems to be your best bet for getting the users of RoleB assigned to RoleA.  You'll get an ArrayList of UserInfo objects.  You can access each item in the ArrayList with

For Each user as UserInfo in usersList
'call AddUserRole() for the current user object

..
Next

Hope that helps,


Brian Dukes
Engage Software
St. Louis, MO
866-907-4002
DNN partner specializing in custom, enterprise DNN development.
 
New Post
8/14/2008 4:52 PM
 

I am still getting "ERROR: Object reference not set to an instance of an object." If the Role does exist, it works perfect. Only when having to create the role, it gives error.

Protected Sub CreateButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CreateButton.Click
            Try
                Dim objRoles As New RoleController
                Dim UserName1 As String = Coach.Text
                Dim CoachRoleName As String = (SchoolNS.Text & "-Coach")
                Dim userEmail As String = Membership.GetUser(UserName1).Email
                Dim userId As Integer = UserController.GetUserByName(0, UserName1).UserID
                Dim roleId As String = objRoles.GetRoleByName(PortalSettings.PortalId, CoachRoleName).RoleID
                Dim objRoleInfo As New RoleInfo
                Dim objRoleController As DotNetNuke.Security.Roles.RoleController
                objRoleController = New DotNetNuke.Security.Roles.RoleController
                If roleId IsNot Nothing Then
                    'do nothing
                Else
                    objRoleInfo.AutoAssignment = False
                    objRoleInfo.BillingFrequency = "Month"
                    objRoleInfo.BillingPeriod = 6
                    objRoleInfo.Description = SchoolNS.Text & "Coach Role"
                    objRoleInfo.IsPublic = False
                    objRoleInfo.PortalID = 0
                    objRoleInfo.RoleID = roleId
                    objRoleInfo.RoleName = CoachRoleName
                    objRoleInfo.ServiceFee = "0.00"
                    objRoleController.AddRole(objRoleInfo)
                End If
                objRoleController.AddUserRole(PortalSettings.PortalId, userId, roleId, Null.NullDate, Null.NullDate)
                errorLabel.Text = "Completed"
            Catch ex As Exception
                errorLabel.Text = "ERROR: " & ex.Message.ToString()
            End Try
        End Sub

 
New Post
8/14/2008 5:06 PM
 

It's happening on the line:

Dim roleId As String = objRoles.GetRoleByName(PortalSettings.PortalId, CoachRoleName).RoleID

You can't call .RoleID is the role is Nothing.  It's here that you need to, first, get a reference to the RoleInfo object, second, test if the role IsNot Nothing, and, only then, ask for its RoleID.  Does that make sense?


Brian Dukes
Engage Software
St. Louis, MO
866-907-4002
DNN partner specializing in custom, enterprise DNN development.
 
New Post
8/14/2008 10:26 PM
 

Brian, that does make perfect sense but I cannot figure out how to do what you suggested.

I got the reference (Dim roleId As String = objRoles.GetRoleByName(PortalSettings.PortalId, CoachRoleName).RoleID)

I checked if it IsNot Nothing (If roleId IsNot Nothing Then)

Now what do you mean "and, only then, ask for its RoleID" how can it have a RoleId if it is Null? dosnt it have to assign a new RoleID for the new role? I tried just leaving out the objRoleInfo.RoleId but that caused the same error.
               
               

 
New Post
8/15/2008 10:29 AM
 

You need to assign the RoleInfo object returned from GetRoleByName into its own variable, and test if it is null before you call .RoleId.  You do not have to assign a RoleId to the new role.  After your save the new role object, it should be assigned a RoleId.  I've reworked your code a bit for you.  I added checks for null on both the user and role objects, consolidated some duplicate objects that weren't needed, and added the use of Me.PortalId instead of 0 (you never know when your code will get used in a way differently that you originally intended, so it's best to be safe, especially when PortalId is so easy to get).

Protected Sub CreateButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CreateButton.Click
  Try
    Dim objRoles As New RoleController()
    Dim UserName1 As String = Coach.Text
    Dim CoachRoleName As String = (SchoolNS.Text & "-Coach")
   
    Dim user as UserInfo = UserController.GetUserByName(Me.PortalId, UserName1)
    if user Is Nothing Then
      Return
    End If
   
    Dim userId As Integer = user.UserID
    Dim objRoleInfo as RoleInfo = objRoles.GetRoleByName(PortalSettings.PortalId, CoachRoleName)
    if objRoleInfo Is Nothing Then
      objRoleInfo = New RoleInfo()
      objRoleInfo.AutoAssignment = False
      objRoleInfo.BillingFrequency = "Month"
      objRoleInfo.BillingPeriod = 6
      objRoleInfo.Description = SchoolNS.Text & "Coach Role"
      objRoleInfo.IsPublic = False
      objRoleInfo.PortalID = Me.PortalId
      objRoleInfo.RoleName = CoachRoleName
      objRoleInfo.ServiceFee = "0.00"
      objRoles.AddRole(objRoleInfo)
    End If
    objRoleController.AddUserRole(Me.PortalId, userId, objRoleInfo.RoleId, Null.NullDate, Null.NullDate)
    errorLabel.Text = "Completed"
  Catch ex As Exception
    errorLabel.Text = "ERROR: " & ex.Message.ToString()
  End Try
End Sub

Hope it helps,


Brian Dukes
Engage Software
St. Louis, MO
866-907-4002
DNN partner specializing in custom, enterprise DNN development.
 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0BC30469: Reference to a non-shared member requires an object referenceBC30469: Reference to a non-shared member requires an object reference


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out