Fos icon indicating copy to clipboard operation
Fos copied to clipboard

FOS throws ArgumentException when using WebApi middleware

Open mikdav opened this issue 6 years ago • 0 comments

I got FOS from nuget and tried to use it with Microsoft.AspNet.WebApi.Owin, and got the following exception when making a request:

System.ArgumentException: Cannot bind to the target method because its signature or security transparency is not compatible with that of the delegate type. at System.Delegate.CreateDelegate(Type type, Object target, String method, Boolean ignoreCase, Boolean throwOnBindFailure) at Fos.Owin.OwinMiddleware.BuildHandler() at Fos.Owin.OwinMiddleware.get_Handler() at Fos.Owin.OwinMiddleware.Invoke(IDictionary`2 owinParameters) at Fos.Listener.FosRequest.ProcessRequest()

I cloned the repository and debugged through it. The problem appears to be that FosAppBuilder expects all middleware to have an Invoke method can be created as a delegate of type Func<IDictionary<string, object>, Task>. Several of the newer middlewares have an invoke method signature of Func<Microsoft.Owin.IOwinContext, Task>. The System.Web.Http.Owin,HttpMessageHandlerAdapter middleware registered by UseWebApi() is one of these middlewares.

Microsoft.Owin.Builder.AppBuilder already handles conversion between these two signatures and by having FosAppBuilder inherit from Microsoft.Owin.Builder.AppBuilder, I was able to successfully use the WebApi middleware over fastcgi for my application.

mikdav avatar May 16 '18 12:05 mikdav