Skip to content

The value cannot be null or empty. (Parameter 'mediaType') #1999

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
guyulmaz opened this issue Jan 15, 2023 · 1 comment
Closed

The value cannot be null or empty. (Parameter 'mediaType') #1999

guyulmaz opened this issue Jan 15, 2023 · 1 comment

Comments

@guyulmaz
Copy link

DO NOT USE ISSUES FOR QUESTIONS

Describe the bug
A clear and concise description of what the bug is.
Hint: use a tool like https://requestbin.com to compare working and non-working requests.

.net 7 is giving this error. .net 6 dont have this problem.

var client = new RestClient();
var request = new RestRequest("...api", Method.Post);
request.AlwaysMultipartFormData = true;
request.AddParameter("x", "y");
request.AddParameter("xx", "yy");...
return await client.ExecuteAsync(request);

System.AggregateException: One or more errors occurred. (The value cannot be null or empty. (Parameter 'mediaType')) ---> System.ArgumentException: The value cannot be null or empty. (Parameter 'mediaType')
at System.Net.Http.Headers.MediaTypeHeaderValue.CheckMediaTypeFormat(String mediaType, String parameterName)
at System.Net.Http.StringContent..ctor(String content, Encoding encoding, String mediaType)
at RestSharp.RequestContent.AddPostParameters(ParametersCollection postParameters)
at RestSharp.RequestContent.BuildContent()
at RestSharp.RestClient.ExecuteInternal(RestRequest request, CancellationToken cancellationToken)
at RestSharp.RestClient.ExecuteAsync(RestRequest request, CancellationToken cancellationToken)

To Reproduce
Steps to reproduce the behavior, preferably using a code snippet.
Post the non-working request here as well if you made it work using Postman, Swagger, or any other client.

Expected behavior
A clear and concise description of what you expected to happen.
Post the working request here as well if you made it work using Postman, Swagger, or any other client.
You can use https://requestbin.com/r to create a public request bin and share the link in the issue.

Stack trace
Copy the full stack trace here if you get an exception.

Desktop (please complete the following information):

  • OS: [e.g. macOS]
  • .NET version [e.g. .NET 5]
  • Version [e.g. 107.0.4]
    .net 7.0.2
    windows 10
    restsharp 108.0.3

Additional context
Add any other context about the problem here.

@guyulmaz guyulmaz added the bug label Jan 15, 2023
@alexeyzimarev
Copy link
Member

Duplicate of #1969

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants