Kyl*_*vak 4 .net c# autofac asp.net-web-api
我一直在努力让ASP Web API/Autofac集成工作.我创建了一个简单的项目,其中一个Controller返回一个字符串,并且能够成功运行该应用程序.但是,当我将Autofac集成到解决方案中时,在运行时我会收到一个System.EntryPointNotFoundException: Entry point was not found.
以下是在我的机器上创建项目时包含的库版本(减去Autofac库).我从Nuget获得Autofac库,所有其他库都在本地安装.
我把Autofac代码放在我的Register方法中,如下所示:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
//Other code left out for brevity
var builder = new ContainerBuilder();
builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
// Set the dependency resolver to be Autofac.
var container = builder.Build();
config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
}
}
Run Code Online (Sandbox Code Playgroud)
我EntryPointNotFoundException在Application_Start方法中收到一个:
public class WebApiApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
GlobalConfiguration.Configure(WebApiConfig.Register);
}
}
Run Code Online (Sandbox Code Playgroud)
那么我通过Nuget 升级所有包并得到这些版本:
此部分现在插入到web.config文件中:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.5.0.0" newVersion="3.5.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Run Code Online (Sandbox Code Playgroud)
当我再次运行应用程序时,我仍然收到 System.EntryPointNotFoundException: Entry point was not found.
我在这里错过了什么让Autofac和Web API很好地一起玩?
谢谢,凯尔
我想出了这个问题.您需要确保Autofac的版本与Web API的版本兼容.就我而言,我使用的是Web API 2.2库,但Autofac版本标记为Autofac ASP.NET Web API Integration.一旦我切换到Autofac ASP.NET Web API 2.2集成,那么我的解决方案就可以了.毫无疑问,一个微妙的差异,很容易假设你正在使用正确的版本.
凯尔

| 归档时间: |
|
| 查看次数: |
2969 次 |
| 最近记录: |