无法使用 webservice 加载文件或程序集 'Autofac,版本 = 2.6.1.841

问题描述 投票:0回答:1

我正在使用 IoC 在 Sharepoint 上构建 Web 服务。

这是我的主要代码:

[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:无法加载文件或程序集“Autofac,Version=2.6.1.841,Culture=neutral,PublicKeyToken=17863af14b0044da”或其依赖项之一。系统找不到指定的文件。
在 SOAP_WebService.WebService.DisplayArticles()

它说找不到文件,但是 bin/debug 文件夹中存在版本为 2.6.1.841 的

Autofac.dll
。我正在使用这个版本的 Autofac,因为在 Sharepoint 2010 上工作,我只能选择 .NET framework v3.5,它是在这个版本的 .NET framework 上运行的最新版本之一。

类似问题中提供的答案对我没有帮助。

c# web-services sharepoint inversion-of-control autofac
1个回答
0
投票

不知何故我设法解决了......如果有人有类似的问题:

我添加到项目引用中的 Autofac 程序集,Visual Studio 无法找到它,尽管该文件存在于我的项目中(如果有人能解释为什么会发生,我将不胜感激)。解决方案是通过此命令通过开发人员命令提示将此程序集添加到 GAC:

 gacutil /i <path to the assembly> /f
© www.soinside.com 2019 - 2024. All rights reserved.