I am trying to get a clientcontext object by using the PnP.Framework package. The code works fine in a console app but fails when using asp.net code. A couple of references online hinted at using GetContextAsync instead of GetContext. But that fails the same way for me. Here is my modified code to use GetContextAsync. Any advice is appreciated.
try
{
var certificate = X509CertificateUtility.LoadCertificate(StoreName.Root, StoreLocation.LocalMachine, ConfigurationManager.AppSettings["PWAONLINETHUMBPRINT"]);
var am = PnP.Framework.AuthenticationManager.CreateWithCertificate(ConfigurationManager.AppSettings["CLIENTID"], certificate, ConfigurationManager.AppSettings["TENANTID"]);
using (var context = await am.GetContextAsync(siteurl)) <===Hangs here
{
Web web = context.Web;
context.Load(web);
I had the same problem. The fix for me was to change GetContext
to GetContextAsync
. To make async method work, I also needed to change the return types for all methods in that call stack to be async as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With