The request message is too big. the server does not allow messages larger than 2097152 bytes in SharePoint

In this SharePoint tutorial, we will discuss how to fix the error, the request message is too big. the server does not allow messages larger than 2097152 bytes.

Recently, while developing a SharePoint workflow using Visual Studio, we got the below error while saving the workflow definition file inside the host web. If you want to attach the workflow to the host web in SharePoint online, which is developed using Visual Studio, then we can attach it through the XAML file.

Here, we will see how to resolve the error: An unhandled exception of type ‘Microsoft.SharePoint.Client.ServerException’ occurred in Microsoft.SharePoint.Client.Runtime.dll. the request message is too big. the server does not allow messages larger than 2097152 bytes.

We wrote the code below to save the workflow definition file from the app web to the host web. But it is through the below exception in the SaveDefinition method.

WorkflowDeploymentService wfDeploymentService = wfServicesManager.GetWorkflowDeploymentService();

foreach (KeyValuePair<string, string> keyValPair in wfDictionary)
{
RemoveWorkflowDefinition(keyValPair.Key, hostURL);

WorkflowDefinition workflowDef = new WorkflowDefinition(ctx);

workflowDef.Xaml = keyValPair.Value;
workflowDef.DisplayName = keyValPair.Key;

ctx.Load(workflowDef);

wfDeploymentService.SaveDefinition(workflowDef);
ctx.ExecuteQuery();

wfDeploymentService.PublishDefinition(workflowDef.Id);
ctx.ExecuteQuery();

}

The error comes as:

An unhandled exception of type ‘Microsoft.SharePoint.Client.ServerException’ occurred in Microsoft.SharePoint.Client.Runtime.dll

Additional information: the request message is too big. the server does not allow messages larger than 2097152 bytes.

the request message is too big sharepoint online visual studio 2015 workflow
sharepoint the request message is too big

the request message is too big the server does not allow messages larger than 2097152 bytes

Now we will see how to solve the issue “the request message is too big the server does not allow messages larger than 2097152 bytes” in SharePoint Online or SharePoint On-Premises.

SharePoint Online

This is a file size limit imposed by Microsoft within SharePoint Online to prevent uploading file sizes larger than 2MB. Even if the limit is 2MB, the maximum time it does not allow to save even file size more than 1.7MB. So, we need to ensure the workflow definition file does not exceed the limit.

Below are a few things you can try:

  • Remove the unused workflow actions
  • If you have used more WriteToHistory actions, then try to remove the unnecessary actions.
  • Also, we need to remember one more thing: the weightage of different workflow actions is different from one another. For example, WriteToHistory has less size than Calling a Rest API using HttpSend activity.

In SharePoint online, we can not increase the limit also. So, we have to optimize our workflow.

SharePoint 2013/2016/2019

If the above error is coming for the SharePoint on-premise environment, we can increase the upload size limit using PowerShell. Below is the PowerShell command, which we can run in the front-end servers. Then do an IISREST, and the error should not come.

$ws = [Microsoft.SharePoint.Administration.SPWebService]::ContentService

$ws.ClientRequestServiceSettings.MaxReceivedMessageSize = 5120000

$ws.ClientRequestServiceSettings.MaxParseMessageSize = 5120000

$ws.Update()

The above command will increase the upload limit from 2MB to 5MB in SharePoint.

The server does not allow messages larger than 2097152 bytes in Sharepoint

If you are getting the error while uploading documents to a SharePoint document library using CSOM, then you can try to change the code slightly.

If you write like below:

FileCreationInformation.Content=Convert.FromBase64String(data);

Then change the code like below:

FileCreationInformation.Content=new MemoryStream(Convert.FromBase64String(data));

When you use the ContentStream property of the FileCreationInformation class, then there is no file size limit, and the timeout will occur after 30 minutes.

I hope this will be helpful to solve the error: the request message is too big the server does not allow messages larger than 2097152 bytes.

You may also like:

  • While i am using ContentStream, it works up to 240-250mb file after that getting same error.

    “When you use the ContentStream property of the FileCreationInformation class, then there is no file size limit, and the timeout will occur after 30 minutes.”(Its not like that)

  • >