Expand Minimize

Don't forget to call ClientContext.ExecuteQuery()

When you work with the ClientContext and retrieve data it is important to call ClientContext.ExecuteQuery() to send the request to the server.

CheckId SPC019013
TypeName DontOmitExecuteQuery
Severity Warning
Type Assembly

Bad Practice

using (ClientContext context = new ClientContext("http://yourcontexturl"))
{
    Web web = context.Web;
    string webTitle = web.Title;
}

Good Practice
using (ClientContext context = new ClientContext("http://yourcontexturl"))
{
    Web web = context.Web;
    context.Load(web, w => w.Title);
    context.ExecuteQuery();
    string webTitle = web.Title;
}

To suppress this violation in managed code add the following attribute to the method which contains the instruction (available since SPCAF version v5.2). Learn more about SuppressMessage here.

// Important: Ensure to have #define CODE_ANALYSIS at the beginning of your .cs file
[SuppressMessage("SPCAF.Rules.ManagedCSOM.CSOMCorrectnessGroup", "SPC019013:DontOmitExecuteQuery", Justification = "Provide reason for suppression here")]
Disclaimer: The views and opinions expressed in this documentation and in SPCAF do not necessarily reflect the opinions and recommendations of Microsoft or any member of Microsoft. SPCAF and RENCORE are registered trademarks of Rencore. All other trademarks, service marks, collective marks, copyrights, registered names, and marks used or cited by this documentation are the property of their respective owners.