[英]ASP Web API and Autofac Integration Exception
我一直在努力讓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);
}
}
我在Application_Start方法中收到一個EntryPointNotFoundException
:
public class WebApiApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
GlobalConfiguration.Configure(WebApiConfig.Register);
}
}
那么我通過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>
當我再次運行應用程序時,我仍然收到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集成 ,那么我的解決方案就可以了。 毫無疑問,一個微妙的差異,很容易假設你正在使用正確的版本。
凱爾
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.