question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

InvalidDataException: Line length limit 100 exceeded

See original GitHub issue

When uploading data files with RestSharp to a .Net Core 2.1 REST interface, I get this error on some files:

System.IO.InvalidDataException: Line length limit 100 exceeded.
   at Microsoft.AspNetCore.WebUtilities.BufferedReadStream.ReadLineAsync(Int32 lengthLimit, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.WebUtilities.MultipartReaderStream.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.WebUtilities.StreamHelperExtensions.DrainAsync(Stream stream, ArrayPool`1 bytePool, Nullable`1 limit, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.WebUtilities.MultipartReader.ReadNextSectionAsync(CancellationToken cancellationToken)

When I do the same operation with Insomnia, I do not get any error, only with RestSharp.

I have read here https://stackoverflow.com/questions/44642701/microsoft-aspnetcore-webutilities-line-length-limit-100-exceeded that there is a problem with the line ending formats, but this is the only article about it.

The controller signature is very simple:

[HttpPost, DisableRequestSizeLimit]
public async Task<IActionResult> AddPictureAsync(
	IFormFile Picture,
	IFormFile Thumbnail,
	string Title)
{

and the code to send is:

var Request = new RestRequest("picture", Method.POST) { AlwaysMultipartFormData = true };
Request.AddHeader("SessionId", SessionId);
Request.AddFile("Picture", PhotoData.ToArray(), Photo.PhotoUrl);
Request.AddFile("Thumbnail", ThumbnailData, Photo.PhotoUrl.Replace(".jpg", "-t.jpg"));
Request.AddParameter("Title", Photo.Title ?? string.Empty, ParameterType.GetOrPost);

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
thomasd3commented, Nov 7, 2018

Is there an ETA for this? right now I’ve to move code away from RestSharp in order to have the calls succeed.

1reaction
agericcommented, Oct 31, 2018

I’d like to point you gents to https://tools.ietf.org/html/rfc2616. The sequence of characters separating header and body has to be CRLFCRLF, so \r\n\r\n, regardless of what system you’re sending from or to. Anything else and every standardconforming webserver (nginx, haproxy, apache among others) will fail to understand the request properly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Microsoft.AspNetCore.WebUtilities Line length limit 100 ...
I've look at Microsoft.AspNetCore.WebUtilities and found where the error is coming from but not sure how to avoid 100 character limit. I have ......
Read more >
Line length limit 100 exceeded on multipart form request
After debugging the bytes of the incoming request Body, it only has new line characters and no carriage returns which BufferedReadStream ...
Read more >
FormOptions.MultipartBodyLengthLimit Property
Forms sections that exceed this limit will throw an InvalidDataException when parsed. Defaults to 134,217,728 bytes, which is approximately 128MB.
Read more >
Line length limit 100 exceeded on multipart form request
When making the following request on my mac: - curl -X POST \ http://localhost:8080/upload \ -H 'Content-Type: multipart/form-data; ...
Read more >
How do I can fix this: multipart body length limit 16384
i.e. you want to get picture, so the web api read files from server, and return base64 string. and client (xamarin) decode from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found