In C#, when executing ClientContext.ExecuteQuery(), if the query sent to SharePoint has a size above 2MB, it returns an error like this:
The request message is too big. The server does not allow messages larger than 2,097,152 bytes
I have seen this issue is usually found when uploading files. However, in my case this is just a big query that is updating a great quantity of document fields in SharePoint, so no file is involved, just a big list of updated properties, enough to surpass the 2MB limit.
In Javascript, some seem to be able to obtain the size of the current request from the ClientContext. However, this solution does not apply to C#. There is certainly an object named PendingRequest, but I have failed to find a way to obtain this data. WebRequest Content Size is neither a option, since this value is -1, which possibly means this value is set until ExecuteQuery is called.
There is also another solution from 2017 where a garbage collector is used. However, after the first measure, subsequent calls return negative values (for some reason initial total memory is bigger that the final total memory).
Is there a way to find out which is the current size of the pending request in the ClientContext, in order to send the buffered request when it reaches a defined limit? (for example 1 MB)
Thank you!