2014-10-26 69 views
3

我一直试图没有成功获得ASP Web API/Autofac集成工作。我创建了一个简单的项目,其中一个Controller返回一个字符串,并且能够成功运行应用程序。然而,当我融入到Autofac解决方案,在运行时我收到System.EntryPointNotFoundException: Entry point was not found.ASP Web API和Autofac集成异常

  • 的Visual Studio Pro的2013
  • .NET 4.5

这里是包含在项目库中的版本,当我创建它在我的机器上(不包括Autofac库)。我从Nuget获得Autofac库,所有其他库都在本地安装。

  • 的System.Web 4.0
  • System.Web.Extensions程序4.0
  • System.Web.Http 5.0
  • System.Web.Http.WebHost 5.0
  • System.Web.Services 4.0
  • Autofac 3.0 /说明说3.1.5
  • Autofac.Integration.WebApi 3.0 /描述说3.1

我把Autofac代码在我的注册方法是这样的:

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); 
    } 
} 

我收到EntryPointNotFoundException在Application_Start方法:

public class WebApiApplication : System.Web.HttpApplication 
{ 
    protected void Application_Start() 
    { 
     GlobalConfiguration.Configure(WebApiConfig.Register); 
    } 
} 

于是我通过的NuGet和升级ALL包得到这些版本:

  • System.Web 4.0
  • System.Web.Extensions程序4.0
  • System.Web.Http 5.2.2
  • System.Web.Http.WebHost 5.2.2
  • System.Web.Services 4.0
  • Autofac 3.5 /描述说:3.5 0.2
  • Autofac.Integration.WebApi 3.0 /描述说3.1.0

这个片段就是现在插入到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> 

当我再次运行应用程序,我仍然收到System.EntryPointNotFoundException: Entry point was not found.

缺少什么我在这里得到Autofac和Web API很好地一起玩?

谢谢,凯尔

+0

你如何举办的applcation?在IIS中还是使用IIS Express?你可以在新创建的项目中重现这个错误吗?我只能找到一个有点相关的文章:http://www.aaron-powell.com/posts/2010-04-08-problems-with-assembly-trust.html – nemesv 2014-10-26 16:50:11

回答

5

我想通了这个问题。您需要确保Autofac的版本与Web API的版本兼容。在我的情况下,我使用的是Web API 2.2库,但Autofac版本标记为Autofac ASP。NET Web API集成。一旦我切换到Autofac ASP.NET Web API 2.2集成,然后我的解决方案工作。毫无疑问,容易假设你使用的是正确的版本。

凯尔

enter image description here

+0

类似的问题,但相同的答案。我没有使用WebApi(只是常规的MVC),但是由于'Autofac.Mvc5'的版本太新了(或者什么),它与我安装的'Autofac'软件包的版本不兼容。旧的'Autofac'和'Autofac.Mvc5':3.4.0和3.3.4。解决问题的新版本分别为3.5.2和3.3.4。 – 2015-06-05 00:40:07