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

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesAddUserRole errorAddUserRole error
Previous
 
Next
New Post
3/31/2010 12:13 PM
 

 Any idea why this throws an exception when AddUserRole is called?

 
            oUserInfo = UserController.GetUserByName(PortalId, emailParts[0]);
            DotNetNuke.Security.Roles.RoleController rC = new DotNetNuke.Security.Roles.RoleController();
            DotNetNuke.Security.Roles.RoleInfo rI = rC.GetRoleByName(PortalId, "SIG Members");          
            rC.AddUserRole(oUserInfo.UserID, PortalId,rI.RoleID, DateTime.Now.AddYears(100));
 
The exception is:
 
System.InvalidOperationException: There was an error generating the XML document. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at DotNetNuke.Security.Roles.RoleInfo.get_RoleType()
   at DotNetNuke.Security.Roles.RoleInfo.WriteXml(XmlWriter writer)
   at System.Xml.Serialization.XmlSerializationWriter.WriteSerializable(IXmlSerializable serializable, String name, String ns, Boolean isNullable, Boolean wrapped)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterUserRoleInfo.Write1_UserRoleInfo(Object o)
   --- End of inner exception stack trace ---
   at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
   at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o, XmlSerializerNamespaces namespaces)
   at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o)
   at DotNetNuke.Common.Utilities.XmlUtils.Serialize(Object obj)
   at DotNetNuke.Services.Log.EventLog.EventLogController.AddLog(Object objCBO, PortalSettings _PortalSettings, Int32 UserID, String UserName, String LogType)
   at DotNetNuke.Services.Log.EventLog.EventLogController.AddLog(Object objCBO, PortalSettings _PortalSettings, Int32 UserID, String UserName, EventLogType objLogType)
   at DotNetNuke.Security.Roles.RoleController.AddUserRole(Int32 PortalID, Int32 UserId, Int32 RoleId, DateTime EffectiveDate, DateTime ExpiryDate)
   at DotNetNuke.Security.Roles.RoleController.AddUserRole(Int32 PortalID, Int32 UserId, Int32 RoleId, DateTime ExpiryDate)
   at PMIMembershipUpdate.addNewUser(String[] theData) in c:\inetpub\wwwroot\DNN521\Website\DesktopModules\PMIMembershipUpdate\PMIMembershipUpdate.ascx.cs:line 218 
 
Thanks for any advice.




Joe Craig
Patapsco Research Group, Ellicott City, MD
DotNetNuke Development and Services (http://patapscorg.com)
 
New Post
3/31/2010 1:14 PM
 

In your call to AddUserRole, the PortalId and UserID parameters should be reversed. Easy mistake to make - one of the reasons that I like to keep a second instance of VS open to the DNN framework source code when I'm writing module code.


Bill, WESNet Designs
Team Lead - DotNetNuke Gallery Module Project (Not Actively Being Developed)
Extensions Forge Projects . . .
Current: UserExport, ContentDeJour, ePrayer, DNN NewsTicker, By Invitation
Coming Soon: FRBO-For Rent By Owner
 
New Post
3/31/2010 1:33 PM
 

 Thanks so much.  That's one of those errors that you NEVER see because you're looking so hard for something that's WRONG ... and it's so obvious!  <g>




Joe Craig
Patapsco Research Group, Ellicott City, MD
DotNetNuke Development and Services (http://patapscorg.com)
 
New Post
3/31/2010 2:08 PM
 
OK ... with that fixed, AddUserRole does't throw an exception. It seems to work, but the role is not added. Is there something else that is needed?



Joe Craig
Patapsco Research Group, Ellicott City, MD
DotNetNuke Development and Services (http://patapscorg.com)
 
New Post
3/31/2010 2:12 PM
 
Geez! Same mistake twice ...



Joe Craig
Patapsco Research Group, Ellicott City, MD
DotNetNuke Development and Services (http://patapscorg.com)
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesAddUserRole errorAddUserRole error


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