Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PnP.Framework with AuthenticationManager hangs with GetContext

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);
like image 509
JakeUT Avatar asked Oct 19 '25 19:10

JakeUT


1 Answers

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.

like image 110
Mato Skok Avatar answered Oct 23 '25 08:10

Mato Skok