PnP Framework, Client Context Hangs

Viewed 478

I have been working on this for hours now and can't figure out even how to diagnose this issue. When I run this code and step through it, I get an AuthenticationManager class initated but when it goes to create the client context, It just hangs. No error, No break, No exception. Sits there and idles forever.

Thanks for the help, this has been driving me crazy for way to long.

Here is my code (Personal Information has been changed obviously)

public static class SharepointAPI
{
    private static ClientContext cc { get; set; }

    private static void GenVar()
    {
        if(cc == null)
        {
            string appId = "a9f346f5-7229-4127-bfa2-7605c4593ca6";
            var scopes = new string[] { "https://contoso.sharepoint.com/.default" };
            string siteURL = "https://contoso.sharepoint.com/sites/HR/";
            string tenant = "contoso.onmicrosoft.com";
            string certpath = Directory.GetCurrentDirectory() + "\\cert.pfx";
            string certpass = @"Password123";
            var certificate509 = GetCertificate(certpath, certpass);
            cc = new PnP.Framework.AuthenticationManager(clientId: appId, certificate: certificate509, tenantId: tenant)
                .GetContext(siteURL);

        }
        else
        {
            return;
        }    
    }
    private static X509Certificate2 GetCertificate(string filename, string pwd)
    {
        var certificate = new X509Certificate2(filename, pwd);
        return certificate;
    }
2 Answers

This is t really an answer but I ended up going back to framework instead of core and used the old PnP.DEV and have had great success. No issues. So that is actually quite a bummer because I really wanted to italics core but oh well.

I don't know about your scenario, but for me I had to use GetContextAsync().

This was in WPF, and it was when a method was called off the back of an update to a DependencyProperty.

Therefore, the utility method I had built had to be async so I could await the call to GetContextAsync(), but I guess beyond that point you could just use GetAwaiter().GetResult() on the call to the utility to make it synchronous if I needed to.

Related