[BUG] The given key '<key_here>' was not present in the dictionary
Describe the bug After updating to v4.7.51 my client stopped to work.
System.Collections.Generic.KeyNotFoundException : The given key '3' was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at Refit.RequestBuilderImplementation.<>c__DisplayClass17_0.<<BuildRequestFactoryForMethod>b__0>d.MoveNext() in d:\a\1\s\Refit\RequestBuilderImplementation.cs:line 616
--- End of stack trace from previous location where exception was thrown ---
at Refit.RequestBuilderImplementation.<>c__DisplayClass14_0`2.<<BuildCancellableTaskFuncForMethod>b__0>d.MoveNext() in d:\a\1\s\Refit\RequestBuilderImplementation.cs:line 244
--- End of stack trace from previous location where exception was thrown ---
Steps To Reproduce
Create Refit client with method signature
[Multipart]
[Post("/companies/{companyId}/{path}")]
Task<ApiResponse<object>> UploadFile(
int companyId,
string path,
[AliasAs("file")] StreamPart stream,
[Header("Authorization")] string authorization,
bool overwrite = false,
[AliasAs("fileMetadata")] string metadata = null);
Expected behavior
Multipart file upload should work. One part of the upload is a file stream Second are form data
Environment
- OS: Windows 10, Windows Server 2016 and Docker containers
- Device:
- Version: v4.7.51
- Working Version: Refit v4.7.9
Additional context
Same bug here. Rollback to 4.7.9 fixes it. My implementation:
[Multipart]
[Post("/blobstorage/{**filepath}")]
Task Blob_Post_Byte(string filepath, [AliasAs("attachment")] ByteArrayPart byteArray);
You are very lucky that you could rollback :) It won't work in my case. 4.7.51 is already used in multiple other nugets in my company. I had to switch to classic typed HttpClient for upload scenarios.
Later I read that putting StreamPart on the first position of the arguments list works fine
Thanks @ppasieka. That fixed it. Been battling with it for hours
I have the same problem with version 4.7.9 for this request
[Delete("/api/v1/video")]
Task Clear([Query] int playerIndex);
I have to stay on version 4.6.107
I'm going to get this pushed to NuGet shortly but please validate that the fixes work for you in 4.8.10 or later -- the package is on the CI feed:
https://dev.azure.com/dotnet/ReactiveUI/_packaging?_a=package&feed=6368ad76-9653-4c2f-a6c6-da8c790ae826&package=2f65cb3b-df09-4050-a84e-b868ed95fd28&preferRelease=true
https://pkgs.dev.azure.com/dotnet/ReactiveUI/_packaging/Refit/nuget/v3/index.json
Thanks @onovotny.
I can confirm that v4.8.10 fixed this bug for me π
Just for reference, here is my code that was failing on v4.7.51 and now works on v4.8.10:
[Post("/PostBlob/{photoTitle}"), Multipart]
Task<PhotoModel> PostPhotoBlob(string photoTitle, [AliasAs("photo")] StreamPart photoStream);
https://github.com/brminnick/AzureBlobStorageSampleApp/blob/4fb40e7accedd83a2d07e50957fee46765366c04/AzureBlobStorageSampleApp/Services/IPhotosAPI.cs#L17-L18
Fixed by #772