0

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.

Stephen
  • 1
  • 1
  • If the CurrentAccessToken is null, there may be an issue with the authentication. Did you check the connection status (`svc.IsReady`) and last error (`svc.LastCrmError`) as described [here](https://learn.microsoft.com/en-us/powerapps/developer/data-platform/xrm-tooling/use-connection-strings-xrm-tooling-connect#determine-your-connection-status)? Please also tag your question correctly (C#) to increase the chance for help. – johnmoarr Mar 17 '22 at 16:34
  • Does this answer your question? [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Elikill58 Mar 18 '22 at 11:05

0 Answers0