C# Unity依赖项解析程序不使用Katana和WebAPI?
我尝试了Unity3在Katana托管的WebAPI 我得到一个异常,启动时无法加载system.web.http 有人做了这件事吗C# Unity依赖项解析程序不使用Katana和WebAPI?,c#,asp.net-web-api,katana,C#,Asp.net Web Api,Katana,我尝试了Unity3在Katana托管的WebAPI 我得到一个异常,启动时无法加载system.web.http 有人做了这件事吗 HttpConfiguration apiConfig = new HttpConfiguration(); apiConfig.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = Rou
HttpConfiguration apiConfig = new HttpConfiguration();
apiConfig.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
apiConfig.Formatters.Remove(apiConfig.Formatters.XmlFormatter);
apiConfig.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
apiConfig.DependencyResolver = new UnityDependencyResolver(_container);
app.UseWebApi(apiConfig);
如果您使用的是Unity.WebAPI包,则它取决于System.Web.Http v4.0。为了在Web API v2中使用它,您需要将程序集绑定重定向添加到Web.config:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
如果您使用的是Unity.WebAPI包,它取决于System.Web.Http v4.0。为了在Web API v2中使用它,您需要将程序集绑定重定向添加到Web.config:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
您是否仍在这里看到问题?我注意到您还有一个问题与参数绑定在Web Api中不起作用有关,您似乎已经解决了这个问题……这仍然是一个问题吗?如果是的话,你能告诉我更详细的错误吗……我没有找到解决办法。我使用autofac IOC作为临时解决方案,它没有问题。(autofac为webapi 5.0打包了一个nuget)创新例外的目标。无法加载System.Web.Http。我以前见过一次与owin相关的错误。我认为这与DLL的版本控制有关。您是否仍然看到问题?我注意到您还有一个问题与参数绑定在Web Api中不起作用有关,您似乎已经解决了这个问题……这仍然是一个问题吗?如果是的话,你能告诉我更详细的错误吗……我没有找到解决办法。我使用autofac IOC作为临时解决方案,它没有问题。(autofac为webapi 5.0打包了一个nuget)创新例外的目标。无法加载System.Web.Http。我以前见过一次与owin相关的错误。我假设它与DLL的版本控制有关。webapi托管在owin中,我没有web.config.Use app.config。webapi托管在owin中,我没有web.config.Use app.config。