We have an SP Online site that has been working fine until recently. Now, when we call the SP authentication manager to get a new client context, I am getting the error 'Object reference not set to an instance of an object'. It's not due to an issue with the client id or secret (we ruled that out by refreshing the client id/secret).

Any thoughts on what might be causing this? I have pasted below the code snippet for the call to get the CC, and the log entries showing the error.

C# code:

var am = new AuthenticationManager();

return am.GetAppOnlyAuthenticatedContext(siteUrl, realm, clientId, clientSecret);

Log entries:

2019-04-30 10:53:19,821 ERROR [NX5UIRGA] [SharePointWorker ] - Request faild System.NullReferenceException: Object reference not set to an instance of an object. at OfficeDevPnP.Core.Utilities.TokenHelper.GetAppOnlyAccessToken(String targetPrincipalName, String targetHost, String targetRealm) at OfficeDevPnP.Core.AuthenticationManager.EnsureToken(String siteUrl, String realm, String appId, String appSecret, String acsHostUrl, String globalEndPointPrefix)

  • I am facing similar issue. Any luck here? Aug 17, 2019 at 2:29

1 Answer 1


I have tried using my application id, secret to a url of the site in SPO environment and I am able to get the context. Please check the site url and the credentials one more time. I don't see anything wrong here.

Try without realm. Pass just siteurl, clientid, clientsecret and see.


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.