0

I am using below code to access site/web but keep getting "The type of data at position 1206 is different than the one expected." error.

We have two separate tenants and getting this error in one of the tenant.

hope someone can help

SharePointPnPCoreOnline - 3.7.1903 (net461)

var siteUrl = "https://<org>.sharepoint.com/sites/testsite/";
var clientID = "";
var clientSecret = "";
using (ClientContext newCtx = new OfficeDevPnP.Core.AuthenticationManager().GetAppOnlyAuthenticatedContext(siteUrl, clientID, clientSecret))
{
    Site _site = newCtx.Site;
    var _web = newCtx.Site.RootWeb;
    newCtx.Load(_site);
    newCtx.Load(_web);
    newCtx.ExecuteQueryRetry();
}

Update

I also tried below code without PnP and it's failing at "context.ExecuteQuery();"

using (var context = new ClientContext(url))
{
    context.Credentials = new SharePointOnlineCredentials(userName, ConvertPassword(password));
    Web web = context.Web;
    Site site = context.Site;

    context.Load(site);
    context.Load(web);
    context.ExecuteQuery();

}

What I have noticed so far is an issue is with "SensitivityLabel" property. so below code is working

using (var context = new ClientContext(url))
{
    context.Credentials = new SharePointOnlineCredentials(userName, ConvertPassword(password));
    Web web = context.Web;
    Site site = context.Site;

    context.Load(site, s=>s.Url);
    context.Load(web);
    context.ExecuteQuery();

}

But as soon as I add "SensitivityLabel" property it stops working with "The type of data at position is different than the one expected" error

using (var context = new ClientContext(url))
{
    context.Credentials = new SharePointOnlineCredentials(userName, ConvertPassword(password));
    Web web = context.Web;
    Site site = context.Site;

    context.Load(site, s=>s.SensitivityLabel);
    context.Load(web);
    context.ExecuteQuery();

}



private static SecureString ConvertPassword(string password)
{
    var securePassword = new SecureString();
    //Convert string to secure string  
    foreach (char c in password)
        securePassword.AppendChar(c);
    securePassword.MakeReadOnly();
    return securePassword;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.