The following forum(s) are migrating to a new home on Microsoft Q&A (Preview): Developing Universal Windows apps!

Ask new questions on Microsoft Q&A (Preview).
Interact with existing posts until December 13, 2019, after which content will be closed to all new and existing posts.

Learn More

 none
[UWP][C#]User object FirstName and LastName are not working when user is offline RRS feed

  • Question

  • Hi All,

    we have developed small universal class library for getting user display name, first name, last name and domain. We have used new User API.

    When my PC connected to internet, we can retrieve all the values. But when we don't have internet connection, we can only get Display name and domain, other first name and last name are empty.

    It doesn't through any exception also. you can reproduce this using Windows universal sample

    In our universal we have used following code to retrieve:

    using System;
    using System.Linq;
    using System.Threading;
    using System.Threading.Tasks;
    using Windows.System;
    
    namespace UserInfoLib
    {
        public class UserInfo
        {
            private static async Task<User> GetUserObject()
            {
                var users = await User.FindAllAsync();
                return users.ToList().Where(user => user.AuthenticationStatus != UserAuthenticationStatus.Unauthenticated).FirstOrDefault();
            }
    
            public static string GetDisplayName()
            {
                string DisplayName = string.Empty;
                AutoResetEvent ar = new AutoResetEvent(false);
                try
                {
                    Task.Run(async () =>
                    {
                        User user = await GetUserObject();
                        DisplayName = (string)await user.GetPropertyAsync(KnownUserProperties.DisplayName);
                        ar.Set();
                    });
    
                    ar.WaitOne();
    
                    return DisplayName;
                }
                catch (Exception e)
                {
                }
    
                return string.Empty;
            }
    
            public static string GetFirstName()
            {
                string FirstName = string.Empty;
                AutoResetEvent ar = new AutoResetEvent(false);
                try
                {
                    Task.Run(async () =>
                    {
                        User user = await GetUserObject();
                        FirstName = (string)await user.GetPropertyAsync(KnownUserProperties.FirstName);
                        ar.Set();
                    });
    
                    ar.WaitOne();
    
                    return FirstName;
                }
                catch (Exception e)
                {
                }
    
                return string.Empty;
            }
    
            public static string GetLastName()
            {
                string lastName = string.Empty;
                AutoResetEvent ar = new AutoResetEvent(false);
                try
                {
                    Task.Run(async () =>
                    {
                        User user = await GetUserObject();
                        lastName = (string)await user.GetPropertyAsync(KnownUserProperties.LastName);
                        ar.Set();
                    });
    
                    ar.WaitOne();
    
                    return lastName;
                }
                catch (Exception e)
                {
                }
    
                return string.Empty;
            }
    
            public static string GetDomainName()
            {
                string DomainName = string.Empty;
                AutoResetEvent ar = new AutoResetEvent(false);
                try
                {
                    Task.Run(async () =>
                    {
                        User user = await GetUserObject();
                        DomainName = (string)await user.GetPropertyAsync(KnownUserProperties.DomainName);
                        ar.Set();
                    });
    
                    ar.WaitOne();
    
                    return DomainName;
                }
                catch (Exception e)
                {
                }
    
                return string.Empty;
            }
    
        }
    }

    Please help us to understand the behavior. We have not found any documents for behavior difference online vs offline.

    Feel free to ask any required information

    Thanks,


    Pallam Madhukar Windows Phone Developer


    Monday, July 9, 2018 7:40 AM

All replies

  • Hi,

    I could not reproduce the problem with the official sample and the code snippet you gave. 

    What's the OS version of the device and what's the target version of the device?

    Have you tried to run it on other devices to see if the problem still exist?

    Generally, user class will access the local user profile and it does not request for the internet. You could check this in the sample as it does not request for internet capability.

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, July 10, 2018 2:31 AM
    Moderator
  • Hi Roy,

    Thanks for checking this. We building and running in same machine.

    Device OS Version: 1709 ( OS Build: 16299.15)

    Please try the sample that we are checking, So that we can identify the configuration related issues.

    Thanks,


    Pallam Madhukar Windows Phone Developer

    Tuesday, July 10, 2018 5:38 AM
  • Hi,

    I'm running your sample on build 17134, I still could get the name. Like this:

    Could you please made a test on other device with build 17134?

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, July 11, 2018 7:26 AM
    Moderator
  • Hi Roy,

    Please can check this video and able to reproduce this issue all the time. You can observe the First Name and Last Name only received when Windows 10 Device is connected to the internet. 

    Please help us find the root cause of this issue. Unfortunately, we do not have build 17134. It important for our customers to use this API any version of Windows 10. 

    Any suggestions or workaround is appreciated and helpful.

    Thanks,


    Pallam Madhukar Windows Phone Developer

    Thursday, August 9, 2018 11:08 AM
  • Hi ,

    This problem is strange and it is not suitable to discuss via the forum. It needs more professional support. I suggest that you might need to open a support ticket for this. Please contact our paid phone support at MS Support. You will get 1:1 support on that. Please kindly note that your support ticket will be free if it is Microsoft's issue.

    Best regards,

    Roy

     


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, August 10, 2018 8:34 AM
    Moderator