I'm developing a Windows 8.1 App (XAML/C#) with MVVM Light.
I used to keep my LiveId inside the code just for debugging, but now it's time to do the LogIn.
Currently i'm stuck with this piece of code:
this.authClient = new LiveAuthClient();
LiveLoginResult loginResult = await this.authClient.InitializeAsync(scopes);
It keeps giving me the error:
An exception of type 'System.NullReferenceException' occurred in mscorlib.dll but was not handled in user code
Additional information: Object reference not set to an instance of an object.
Source Code:
private static readonly string[] scopes =
new string[] {
"wl.signin",
"wl.basic",
"wl.offline_access"};
private LiveAuthClient authClient;
private LiveConnectClient liveClient;
public DashboardView()
{
this.InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
this.InitializePage();
}
private async void InitializePage()
{
this.authClient = new LiveAuthClient();
LiveLoginResult loginResult = await this.authClient.InitializeAsync(scopes);
if (loginResult.Status == LiveConnectSessionStatus.Connected)
{
if (this.authClient.CanLogout)
{
this.btnLogin.Content = "Sign Out";
}
else
{
this.btnLogin.Visibility = Visibility.Collapsed;
}
this.liveClient = new LiveConnectClient(loginResult.Session);
this.GetMe();
}
}
private async void btnLogin_Click(object sender, RoutedEventArgs e)
{
if (this.btnLogin.Content.ToString() == "Sign In")
{
LiveLoginResult loginResult = await this.authClient.LoginAsync(scopes);
if (loginResult.Status == LiveConnectSessionStatus.Connected)
{
if (this.authClient.CanLogout)
{
this.btnLogin.Content = "Sign Out";
}
else
{
this.btnLogin.Visibility = Visibility.Collapsed;
}
this.liveClient = new LiveConnectClient(loginResult.Session);
this.GetMe();
}
}
else
{
this.authClient.Logout();
this.btnLogin.Content = "Sign In";
}
}
private async void GetMe()
{
Task<LiveOperationResult> task = this.liveClient.GetAsync("me");
var result = await task;
dynamic profile = result.Result;
}
I even tried some different scopes and this was my last try.
Thanks in advance.