- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
mediaType null or empty when using RestSharp 108.0.2 with .NET 7 #1969
Comments
Sorry but the issue doesn't tell enough to diagnose the problem or even understand what the problem is. Please provide more details following the issue template. |
@alexeyzimarev Sorry, I was in a rush. I hope it is more clear now. |
I get the same thing with the same version and .NET 7 using the AddFile method request.AddFile("attachment", attachment.FileBytes, attachment.FileName); Also tried passing a content type and same error when var response = client.ExecuteAsync(request); is called. The value cannot be null or empty. (Parameter 'mediaType') Happy to complete another issue, but the subject is the exactly the same, even if the method to get there is slightly different. |
When changing the TargetFrameworks of RestSharp to I have looked at the microsoft implementation and there are some changes. .net6.0 implements a check to use the DefaultMediaType fallback when the given mediaType is null.
.net7.0 deimplements the check and changed the method signature (questionmark is removed)
|
.NET seven will be added as a direct target for v109 and will be executing tests for the target SDKs in the pipeline. We'll see what fails and what requires fixing. Thanks for reporting. I haven't seen this particular one in the list of breaking changes. I guess, in time we might get more of those, unfortunately. |
Ok, basically the fix is to provide the default value for the |
The workaround for the current RS version would be to add the |
Testing now, i’ll report back. |
I haven't seen failed tests with files. I only reproduced the multipart form issue, and the workaround applies there. I will double check the tests for |
I’ll create a test project if I have to. This call with or without the type results in the same error me i fortunatly. :( |
@jhudsonWA you can start by looking at current tests that use |
Ok, I was barking up the wrong tree. AddFile does work great. AddFile on a request along with other post data is a Multipart Form Data situation and would run into this bug. I tested adding the latest 109 (compiled from the source) and the issue is confirmed fixed. |
I can confirm that the issue in my project is resolved with RestSharp 109.0.0-preview.1 |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
|
* Added .NET Framework 471 as a target. .NET 5 is out * Fix the media type issue with .NET 7 #1969 * `IRestClient` Interface is back * String type for ContentType * Added Authenticator to RestRequest * Made Options immutable to make the client thread-safe * Ignore exceptions parsing response cookies (#2015) * V109 (#2010) * Added a simple factory with opt-in --------- Co-authored-by: Francesc Castells <fcastells76@gmail.com> Co-authored-by: Francesc Castells <francesc.castells@sermo.com> Co-authored-by: Edward Lichtman <E.Lichtman2@gmail.com>
How? Could someone be so kind to help with a piece of practical and useable advice? |
It's shown right there #1969 (comment) It depends on the parameter type which fails with null media type in your code. |
Describe the bug
After changing target framework from .NET 6 to .NET 7 the following code in a Blazor server side application started to throw an exception (no matter if individual packages are referenced using their 6.0.10 or 7.0.0 versions):
var request = new RestRequest(BaseUrl + "waitinglist/" + accessToken);
request.AddParameter("officeNumber", PracticeId);
request.AlwaysMultipartFormData = true;
request.Method = Method.Post;
var response = client.ExecuteAsync(request);
Once I change target framework back to .NET 6, it works again.
To Reproduce
See description above and screenshot attached
Expected behavior
No exception but results returned.
Stack trace
Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer: Warning: Unhandled exception rendering component: 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)
at DPAForPRODUCTNAMEREMOVEDBlazor.Controllers.PRODUCTNAMEREMOVED.DownloadPRODUCTNAMEREMOVEDJSON(Boolean forceDownload) in /Users/christian/projects/Insights-and-Services-for-PRODUCTNAMEREMOVED/DPAForPRODUCTNAMEREMOVEDBlazor/Controllers/PRODUCTNAMEREMOVED.cs:line 297
at DPAForPRODUCTNAMEREMOVEDBlazor.Controllers.PRODUCTNAMEREMOVED.DownloadPRODUCTNAMEREMOVEDJSON() in /Users/christian/projects/Insights-and-Services-for-PRODUCTNAMEREMOVED/DPAForPRODUCTNAMEREMOVEDBlazor/Controllers/PRODUCTNAMEREMOVED.cs:line 198
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at MudBlazor.MudBaseButton.OnClickHandler(MouseEventArgs ev)
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
fail: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]
Unhandled exception in circuit '3hFrvBILVAv_71c7LL_TtxPkV0PGJNviJWzjwzYOQgQ'.
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)
at DPAForPRODUCTNAMEREMOVEDBlazor.Controllers.PRODUCTNAMEREMOVED.DownloadPRODUCTNAMEREMOVEDJSON(Boolean forceDownload) in /Users/christian/projects/Insights-and-Services-for-PRODUCTNAMEREMOVED/DPAForPRODUCTNAMEREMOVEDBlazor/Controllers/PRODUCTNAMEREMOVED.cs:line 297
at DPAForPRODUCTNAMEREMOVEDBlazor.Controllers.PRODUCTNAMEREMOVED.DownloadPRODUCTNAMEREMOVEDJSON() in /Users/christian/projects/Insights-and-Services-for-PRODUCTNAMEREMOVED/DPAForPRODUCTNAMEREMOVEDBlazor/Controllers/PRODUCTNAMEREMOVED.cs:line 198
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at MudBlazor.MudBaseButton.OnClickHandler(MouseEventArgs ev)
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost: Error: Unhandled exception in circuit '3hFrvBILVAv_71c7LL_TtxPkV0PGJNviJWzjwzYOQgQ'.
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)
at DPAForPRODUCTNAMEREMOVEDBlazor.Controllers.PRODUCTNAMEREMOVED.DownloadPRODUCTNAMEREMOVEDJSON(Boolean forceDownload) in /Users/christian/projects/Insights-and-Services-for-PRODUCTNAMEREMOVED/DPAForPRODUCTNAMEREMOVEDBlazor/Controllers/PRODUCTNAMEREMOVED.cs:line 297
at DPAForPRODUCTNAMEREMOVEDBlazor.Controllers.PRODUCTNAMEREMOVED.DownloadPRODUCTNAMEREMOVEDJSON() in /Users/christian/projects/Insights-and-Services-for-PRODUCTNAMEREMOVED/DPAForPRODUCTNAMEREMOVEDBlazor/Controllers/PRODUCTNAMEREMOVED.cs:line 198
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at MudBlazor.MudBaseButton.OnClickHandler(MouseEventArgs ev)
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
Desktop (please complete the following information):
Additional context
none
The text was updated successfully, but these errors were encountered: