2017-08-02 28 views
0

我正在使用IoC在SharePoint上構建Web服務。這是我的主要代碼:無法通過web服務加載文件或程序集'Autofac,Version = 2.6.1.841

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1), WebService(Namespace = "http://tempuri.org/")] 
class WebService : System.Web.Services.WebService 
{ 
    private static IContainer Container { get; set; } 
    private DataTable Articles=new DataTable(); 
    private string display; 
    [WebMethod(EnableSession = true, Description = "Web method for using search service")] 
    public string DisplayArticles() 
    { 
     var builder = new ContainerBuilder(); 
     builder.RegisterType<WebServiceRepo>().As<IArticlesRepository>(); 
     Container = builder.Build(); 
     Search(); 
     return display; 
    } 

    public void Search() 
    { 
     using (var scope = Container.BeginLifetimeScope()) 
     { 
      var repo = scope.Resolve<IArticlesRepository>(); 
      Articles.Load(repo.GetArticles(),LoadOption.OverwriteChanges); 
      display = repo.ReturnArticles(Articles); 
     } 
    } 
} 

的問題是在試圖調用使用Autofac方法時,我得到一個錯誤:

System.IO.FileNotFoundException: Could not load file or assembly 'Autofac, Version=2.6.1.841, Culture=neutral, PublicKeyToken=17863af14b0044da' or one of its dependencies. The system cannot find the file specified. 
    at SOAP_WebService.WebService.DisplayArticles() 

它說,關於未找到的文件,而是一個Autofac。在bin/debug文件夾中存在版本爲2.6.1.841的dll。我使用這個版本的autofac是因爲在sharepoint 2010上工作,我只能選擇.net framework v3.5,它是運行在這個.net框架版本上的最新版本之一。

在相似的問題中提供的答案沒有幫助我。

回答

0

不知何故,我設法去解決它,如果還有人將有一個simmiliar問題:

的Autofac總成我加入到我的項目中引用,在某種程度上不可能由Visual Studio發現,儘管事實該文件存在於我的項目中(如果有人會向我解釋爲什麼會發生這種情況,我會很感激)。解決方案是通過此命令通過開發人員命令提示符將此程序集添加到GAC中:

gacutil /i <path to the assembly> /f 
相關問題