Zaid-Ajaj / Fable.Remoting

Type-safe communication layer (RPC-style) for F# featuring Fable and .NET Apps
https://zaid-ajaj.github.io/Fable.Remoting/
MIT License
272 stars 55 forks source link

$Remoting+normalize@60-1' cannot be converted to type 'Microsoft.FSharp.Core.FSharpFunc` #342

Closed RicoSaupeBosch closed 1 year ago

RicoSaupeBosch commented 1 year ago

I have the following situation and appreciate any support/hint/help here.

I have a Giraffe webapi (Net7.0) that provides a Remoting endpoint

 let testRemoting =
        Remoting.createApi()
        |> Remoting.withRouteBuilder ITestApi.RouteBuilder
        |> Remoting.fromValue testApi
        |> Remoting.buildHttpHandler

the Api

type ITestApi = {
    getSites: int -> Async<string>
}
with
    static member RouteBuilder _ method = $"/remoting/test/{method}"    

the client is a Windows Service (net7)/console application which tries to create a proxy.

let testApi =
             Remoting.createApi()
             |> Remoting.withRouteBuilder ITestApi.RouteBuilder
             |> Remoting.withBaseUrl appS.ApiBaseAddress
             |> Remoting.buildProxy<ITestApi>
             services.AddSingleton<ITestApi>(testApi) |> ignore

The issue I am having now is this. I tried with the simplest of types but it won't work.

System.ArgumentException: Object of type '<StartupCode$Fable-Remoting-Client>.$Remoting+normalize@60-1' cannot be converted to type 'Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,Microsoft.FSharp.Control.FSharpAsync`1[System.String]]'.
   at System.RuntimeType.CheckValue(Object& value, ParameterCopyBackAction& copyBack, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
   at System.Reflection.MethodBase.CheckArguments(Span`1 copyOfParameters, IntPtr* byrefParameters, Span`1 shouldCopyBack, ReadOnlySpan`1 parameters, RuntimeType[] sigTypes, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.FSharp.Reflection.Impl.getRecordConstructor@1008.Invoke(Object[] args) in D:\a\_work\1\s\src\FSharp.Core\reflect.fs:line 1009
   at Fable.Remoting.Client.Remoting.buildProxy[a](RemoteBuilderOptions options, Type resolvedType)
   at Program.Pipe #6 input at line 19@30-1.Invoke(HostBuilderContext hCtx, IServiceCollection services) in <somepath>\Program.fs:line 60
   at Microsoft.Extensions.Hosting.HostBuilder.InitializeServiceProvider()
   at Microsoft.Extensions.Hosting.HostBuilder.Build()
   at Program.Pipe #1 input at line 16@17.Invoke(Unit unitVar) in <somepath>\Program.fs:line 69
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvoke[T,TResult](AsyncActivation`1 ctxt, TResult result1, FSharpFunc`2 part2) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 510
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 112

image

I am using these packages

Windows Service

Server/Api

kerams commented 1 year ago

You need to use Fable.Remoting.DotnetClient instead of Fable.Remoting.Client on .NET. The latter is used in JS projects.

RicoSaupeBosch commented 1 year ago

That was just too easy. :) Thanks for this hint. :)