Small width layout Medium width layout Maximum width layout Small text Medium text Large text
     Search
Downloads Downloads Directory Directory Forums Forums Forge Forge Blogs Blogs        Marketplace Marketplace Careers Program Careers
Community › Forums Register  |  

PortalWebHosting
  Ads  
Aspose - The .NET & Java component publisher
 


  Sponsors  

Meet Our Sponsors

DataSprings - Great Ideas. Always Flowing.
R2integrated - formerly bi4ce
Jango Studios - Skins, Modules and Hosting for DotNetNuke
eUKhost.com is commited to offer exceptional UK Windows Web Hosting solutions with quality 24x7 technical support.Our plans support ASP.Net, ASP, ASP.NET Ajax extensions, XML, MSSQL, MySQL, PHP,DNN, multiple domains and Shared SSL as standard.
SmarterTools
Verndale
 


DotNetNuke Forums
 
  Forum  General DotNetN...  Extend It! ( Pr...  BC30469: Reference to a non-shared member requires an object reference
Previous Previous
 
Next Next
New Post 8/14/2008 2:19 PM
User is offline Brian Dukes
477 posts
www.engagesoftware.com
8th Ranked


Re: BC30469: Reference to a non-shared member requires an object reference 

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
314.966.4000

The leading provider of DotNetNuke support, training and custom module development.
 
New Post 8/14/2008 2:52 PM
User is offline RDO
56 posts
10th Ranked


Re: BC30469: Reference to a non-shared member requires an object reference 

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 3:06 PM
User is offline Brian Dukes
477 posts
www.engagesoftware.com
8th Ranked


Re: BC30469: Reference to a non-shared member requires an object reference 

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
314.966.4000

The leading provider of DotNetNuke support, training and custom module development.
 
New Post 8/14/2008 8:26 PM
User is offline RDO
56 posts
10th Ranked


Re: BC30469: Reference to a non-shared member requires an object referencerian 

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 8:29 AM
User is offline Brian Dukes
477 posts
www.engagesoftware.com
8th Ranked


Re: BC30469: Reference to a non-shared member requires an object referencerian 

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
314.966.4000

The leading provider of DotNetNuke support, training and custom module development.
 
Previous Previous
 
Next Next
  Forum  General DotNetN...  Extend It! ( Pr...  BC30469: Reference to a non-shared member requires an object reference
 


Forum Policy

These Discussion Forums are dedicated to the discussion of the DotNetNuke Web Application Framework.

For the benefit of the community and to protect the integrity of the project, 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 DotNetNuke.
2. Discussion or promotion of DotNetNuke product releases under a different brand name are strictly prohibited.
3. No Flaming or Trolling.
4. No Profanity, Racism, or Prejudice.
5. Site Moderators have the final word on approving/removing a thread or post or comment.
6. English language posting only, please.

 


Active Modules, Inc.
Creators of Active Forums, the best forum module for DotNetNuke
www.activemodules.com
DotNetNuke Marketplace - Modules & Skins
The DotNetNuke Marketplace is the official e-commerce gateway for the DNN ecosystem. It's the place to buy and sell DotNetNuke modules, DotNetNuke skins, and other DNN offerings.
DotNetNuke Marketplace
ExactTarget Email Marketing Software and Solutions
ExactTarget delivers on-demand email software solutions for permission-based email marketing. ExactTarget offers solutions that meet the needs of all industry verticals and all size organizations, including SMB, corporate divisions, not-for-profits, large retail/direct marketers, agencies and enterprises.
ExactTarget.com

DotNetNuke Corporation   Terms Of Use  Privacy Statement
DotNetNuke®, DNN®, and the DotNetNuke logo are trademarks of DotNetNuke Corporation
Hosted by MaximumASP