【问题标题】:Can't host web api on owinhost.exe无法在 owinhost.exe 上托管 Web api
【发布时间】:2023-03-12 05:24:01
【问题描述】:

我尝试挂载由 Owinhost.exe 托管的 Web api 应用程序

启动时我收到此错误消息:

Error: System.ArgumentException 
 No conversion available between System.Func2[System.Collections.Generic.IDictionary2[System.String,System.Object],System.Threading.Tasks.Task] and Microsoft.Owin.OwinMiddleware. 
 Parameter name: signature 

我的图书馆项目声明了这一点:

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        HttpConfiguration config = new HttpConfiguration();
        config.Routes.MapHttpRoute(
        "Default",
        "{controller}/{id}",
        new { id = RouteParameter.Optional });
       app.UseWebApi(config);
     }
}

我的包裹是这个:

<packages>
  <package id="Microsoft.AspNet.WebApi.Client" version="5.1.2" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.Core" version="5.1.2" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.Owin" version="5.1.2" targetFramework="net45" />
  <package id="Microsoft.Owin" version="2.1.0" targetFramework="net45" />
  <package id="Newtonsoft.Json" version="4.5.11" targetFramework="net45" />
  <package id="Owin" version="1.0" targetFramework="net45" />
</packages>

有人有想法吗?

【问题讨论】:

    标签: asp.net-web-api owin self-hosting


    【解决方案1】:

    错误的原因是 OwinHost 在项目根目录的 web.config 文件中查找绑定重定向。作为一种解决方法,将 web.config 文件放在当前目录(bin 文件夹的上一层),然后在其中放置以下重定向:

    <?xml version="1.0"?>
      <configuration>
      <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
    

    这是 Web API CodePlex 网站上的问题链接:https://aspnetwebstack.codeplex.com/workitem/2116

    干杯, 托尼

    【讨论】:

      猜你喜欢
      • 2016-04-07
      • 2017-03-26
      • 1970-01-01
      • 2013-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-19
      • 1970-01-01
      相关资源
      最近更新 更多