Search code examples
c#web-servicessharepointinversion-of-controlautofac

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


I'm building a 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 similar questions did not help me.


Solution

  • Somehow I managed to work it out... If anyone will have a similar 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 grateful 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