[Bug]: MissingMethodException on EnsureSuccessfulAsync on WASM
Describe the bug 🐞
Getting this error on a .NET 8 Blazor Web App, when render mode gets to WASM.
crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Method not found: System.Threading.Tasks.Task1<Refit.ApiResponse1<!0>> Refit.ApiResponse1.EnsureSuccessfulAsync() System.MissingMethodException: Method not found: System.Threading.Tasks.Task1<Refit.ApiResponse1<!0>> Refit.ApiResponse1.EnsureSuccessfulAsync()
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[<GetEntryAsync>d__14](<GetEntryAsync>d__14& stateMachine)
Step to reproduce
- Create sample project with .NET 8 Blazor
- Add Refit reference to WeatherForecast
- Call API and ask for EnsureSuccessfulAsync
- See error
Reproduction repository
https://github.com/reactiveui/refit
Expected behavior
Method should be present and request being verified
Screenshots 🖼️
No response
IDE
No response
Operating system
No response
Version
No response
Device
No response
Refit Version
No response
Additional information ℹ️
No response
We are experiencing a similar issue, while building a request. It does work on some machines but not on the others. Presumably the issue is on Windows10, Windows 11 works ok.
System.MissingMethodException: Attempted to access a missing method.
at Refit.SystemTextJsonContentSerializer.ToHttpContent[T](T item)
at Refit.RequestBuilderImplementation.AddBodyToRequest(RestMethodInfoInternal restMethod, Object param, HttpRequestMessage ret) in c:\temp\releaser\refit\Refit\RequestBuilderImplementation.cs:line 888
at Refit.RequestBuilderImplementation.<>c__DisplayClass19_0.<BuildRequestFactoryForMethod>b__0(Object[] paramList) in c:\temp\releaser\refit\Refit\RequestBuilderImplementation.cs:line 683
at Refit.RequestBuilderImplementation.<>c__DisplayClass15_0`2.<<BuildCancellableTaskFuncForMethod>b__0>d.MoveNext() in c:\temp\releaser\refit\Refit\RequestBuilderImplementation.cs:line 320
--- End of stack trace from previous location ---
Hey, does this issue persist when you downgrade refit versions?
To me, a missing method exception suggests that you may have duplicate dlls, although I don't know how this can happen with with System.Text.Json in .Net 8. Iirc Refit only references it for framework versions
Refit is not trim-friendly https://github.com/reactiveui/refit/issues/1389, and it seems like it never will be. When using it in WASM, which trims by default (starting from .NET 7 or 8, I don't remember exactly), you need to either add this library to the exclusion list or disable <PublishTrimmed>.
I have created a fully support AOT, no reflection and almost identical to Refit's usage. Just wonder if it has any help? https://www.nuget.org/packages/HttpClientFiller
HttpClient Filler Code Generate in C# - Refit like but support AOT