简体   繁体   中英

Could not load file or assembly 'Autofac, Version=2.6.1.841 with webservice

I'm building an web service on sharepoint with IoC. Here is my main code:

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

The problem is an error I'm getting when trying to invoke method that uses 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()

It says about file not being found, but an Autofac.dll with version 2.6.1.841 exists in bin/debug folder. I'm using this version of autofac because working on sharepoint 2010, I can only choose .net framework v3.5 and it's one of the newest version that operates on this version of .net framework.

Answers provided in simmiliar questions did not help me.

Somehow i managed to work it out... If anyone will have a simmiliar problem:

The Autofac assembly I added to the references in my project, was somehow impossible to find by visual studio, despite the fact that file existed in my project (I'll be gratefull if someone will explain me why did it happen). The solution to it was adding this assembly to the GAC via Developer Command Prompt by this command:

 gacutil /i <path to the assembly> /f

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM