Null Reference Exception when connecting to ServiceClient

248 views Asked by At

I got the error 'svc.CurrentAccessToken' threw an exception of type 'System.NullReferenceException' when trying to connect to ServiceClient. The error was raised on this line:

WhoAmIResponse response = (WhoAmIResponse)svc.Execute(request);

Here is the code:

var connectionString = @"Url={url}; Username={username}; Password={password}; AuthType=OAuth; RedirectUri = app://58145B91-0C36-4500-8554-080854F2AC97;";


        using (var svc = new CrmServiceClient(connectionString))
        {
            WhoAmIRequest request = new WhoAmIRequest();
            WhoAmIResponse response = (WhoAmIResponse)svc.Execute(request);         
        }

Not sure what is wrong with this. Please advise.

0

There are 0 answers