Skip to content

mediaType null or empty when using RestSharp 108.0.2 with .NET 7 #1969

@cheindel

Description

@cheindel

Bildschirm­foto 2022-11-09 um 22 55 56
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):

  • OS: macOS Ventura 13.0.1
  • .NET version .NET 7.0.100
  • Version 108.0.2

Additional context
none

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions