refit icon indicating copy to clipboard operation
refit copied to clipboard

[Bug]: MissingMethodException on EnsureSuccessfulAsync on WASM

Open alexdrl opened this issue 1 year ago • 4 comments

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

  1. Create sample project with .NET 8 Blazor
  2. Add Refit reference to WeatherForecast
  3. Call API and ask for EnsureSuccessfulAsync
  4. 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

alexdrl avatar Nov 07 '24 08:11 alexdrl

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

PTLMatija avatar Nov 14 '24 13:11 PTLMatija

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

TimothyMakkison avatar Nov 14 '24 19:11 TimothyMakkison

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>.

ScarletKuro avatar Nov 27 '24 12:11 ScarletKuro

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

ghostnguyen avatar Feb 15 '25 09:02 ghostnguyen