【问题标题】:Could not load file or assembly 'Autofac, Version=2.6.1.841 with webservice无法使用 web 服务加载文件或程序集 'Autofac,版本 = 2.6.1.841
【发布时间】:2017-08-02 08:52:54
【问题描述】:

我正在使用 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: 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()

它说找不到文件,但 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】:

    不知怎的,我设法解决了...如果有人遇到类似的问题:

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

     gacutil /i <path to the assembly> /f
    

    【讨论】:

    • 生产环境等其他环境呢?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-12
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    相关资源
    最近更新 更多