refit icon indicating copy to clipboard operation
refit copied to clipboard

[BUG] The given key '<key_here>' was not present in the dictionary

Open ppasieka opened this issue 7 years ago β€’ 7 comments

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

ppasieka avatar Oct 14 '19 10:10 ppasieka

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);

PageEngine avatar Oct 21 '19 15:10 PageEngine

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

ppasieka avatar Oct 21 '19 16:10 ppasieka

Thanks @ppasieka. That fixed it. Been battling with it for hours

igeeksng avatar Oct 24 '19 13:10 igeeksng

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

srollinet avatar Oct 24 '19 13:10 srollinet

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

clairernovotny avatar Oct 30 '19 21:10 clairernovotny

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

TheCodeTraveler avatar Oct 30 '19 21:10 TheCodeTraveler

Fixed by #772

clairernovotny avatar Oct 31 '19 13:10 clairernovotny