octokit / octokit.net

A GitHub API client library for .NET
https://octokitnet.readthedocs.io/en/latest/
MIT License
2.62k stars 1.07k forks source link

[BUG]: exception "mediatype is null or empty" when trying to delete file #2870

Open b3b00 opened 3 months ago

b3b00 commented 3 months ago

What happened?

When trying to delete a file using

var deleteRequest =   new DeleteFileRequest($"delete file", content.content.Sha);
await gitHubClient.Repository.Content.DeleteFile(RepositoryId,$"notes/{noteName}.md" , deleteRequest);

I get the following exception

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 Octokit.Internal.HttpClientAdapter.BuildRequestMessage(IRequest request) in /_/Octokit/Http/HttpClientAdapter.cs:line 147
   at Octokit.Internal.HttpClientAdapter.Send(IRequest request, CancellationToken cancellationToken, Func`2 preprocessResponseBody) in /_/Octokit/Http/HttpClientAdapter.cs:line 48
   at Octokit.Connection.RunRequest(IRequest request, CancellationToken cancellationToken, Func`2 preprocessResponseBody) in /_/Octokit/Http/Connection.cs:line 761
   at Octokit.Connection.Run[T](IRequest request, CancellationToken cancellationToken, Func`2 preprocessResponseBody) in /_/Octokit/Http/Connection.cs:line 752
   at Octokit.Connection.Delete(Uri uri, Object data) in /_/Octokit/Http/Connection.cs:line 602

Versions

latest version : octokit.net v9.1.1 (did not try previous versions)

Relevant log output

No response

Code of Conduct

b3b00 commented 3 months ago

I've debugged and found a quick fix (see https://github.com/octokit/octokit.net/commit/3848a792863a1eff21c0400442dedf9439c4429a). But I guess it's a bit too optimistic as the Connection.Deletemethod may be used to delete other resources that does not need content-type to be setted if no body is send with the HTTP DELETE request.

b3b00 commented 3 months ago

I've forgot to specify my dotnet env :

` SDK .NET : Version: 8.0.101 Commit: 6eceda187b Workload version: 8.0.100-manifests.69afb982

Environnement d'exécution : OS Name: Windows OS Version: 10.0.19044 OS Platform: Windows RID: win-x64 Base Path: C:\Program Files\dotnet\sdk\8.0.101\

Charges de travail .NET installées : Workload version: 8.0.100-manifests.69afb982 Il n'y a aucune charge de travail installée à afficher.

Host: Version: 8.0.1 Architecture: x64 Commit: bf5e279d92 `