We are using ADFS Authenticator module, when we are trying to create a virtual user, we are getting the below error:

Expecting state ‘Element’.. Encountered ‘Text’ with name ”, namespace ”.

Below is the code I am using in my applications.

Sitecore.Security.Accounts.User vuser = Sitecore.Security.Authentication.AuthenticationManager.BuildVirtualUser(“athakur”, true);

  • Do you have a stack trace?
    – maz
    Apr 17, 2018 at 14:20
  • You may need to include a domain in the first parameter passed to BuildVirtualUser.
    – Teeknow
    Apr 18, 2018 at 21:06

1 Answer 1


Here is what worked for me:

                //Specify with the domain name
                var virtualUser = Sitecore.Security.Authentication.AuthenticationManager.BuildVirtualUser(String.Format("extranet\\{0}", user.Email), true);

                // You can add roles to the Virtual user                    virtualUser.Roles.Add(Sitecore.Security.Accounts.Role.FromName("extranet\\Anonymous"));

                // You can even work with the profile if you wish
                virtualUser.Profile.SetCustomProperty("CustomProperty", user.UserName);
                virtualUser.Profile.Email = user.Email;
                virtualUser.Profile.Name = user.DisplayName;
                virtualUser.Profile.FullName = user.UserName;

                virtualUser.Profile.SetCustomProperty("Country", user.Country);

                //And finally, if you wish to login the virtual user                    Sitecore.Security.Authentication.AuthenticationManager.LoginVirtualUser(virtualUser);
  • this code works for sitecore 9.3 version too?
    – saraswathi
    Jul 20, 2023 at 4:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.