【问题标题】:ASP.NET application reference to assembly in programmatically loaded assemblyASP.NET 应用程序对程序加载程序集中的程序集的引用
【发布时间】:2009-04-29 21:05:03
【问题描述】:

我的 ASP.NET 应用程序加载一个程序集并从其中的对象创建一个类实例。程序集本身引用了一个名为“Aspose.Cells.dll”的 dll,它可以毫无问题地访问它,并且与程序集文件本身位于同一路径上。但是,当我对其方法之一进行方法调用时,会出现此错误:

无法加载文件或程序集 'Aspose.Cells, Version=4.1.2.0, Culture=neutral, PublicKeyToken=9a40d5a4b59e5256' 或其依赖项之一。

我认为我需要让我的 ASP.NET 应用程序也引用这个 DLL,但到目前为止我所做的一切都失败了。加载的程序集 DLL 不在 Web 应用程序的根目录中,我希望它不必位于。

我可以像这样加载程序集:

Assembly asm = Assembly.LoadFile(@"D:\Dev\EasyFlow\Plugins\ImportExportLibrary\bin\Debug\Aspose.Cells.dll");

但我不能这样使用:

AppDomain newDomain = AppDomain.CreateDomain("testAspose");
Assembly asm = newDomain.Load(System.IO.File.ReadAllBytes(@"D:\Dev\EasyFlow\Plugins\ImportExportLibrary\bin\Debug\Aspose.Cells.dll"));

有没有更好的方法?

更新:

感谢您的回复。

我忘了提到我不能将程序集复制到 bin 文件夹或 GAC,因为我希望它作为一个插件系统工作,可以通过更改配置文件中程序集的路径轻松替换程序集,而不必手动将文件复制到主项目中。

不过,AssemblyResolve 事件似乎很有趣,我稍后会试一试。

【问题讨论】:

    标签: c# assemblies


    【解决方案1】:

    有几种方法可以做到这一点。 Microsoft 知识库文章中描述了一种方法 “How to load an assembly at runtime that is located in a folder that is not the bin folder of the application”。它提供了一个很好的分步方法。

    【讨论】:

      【解决方案2】:

      您可以将依赖程序集复制到 Bin 文件夹中或将其安装在 GAC 中。

      【讨论】:

        【解决方案3】:

        我想你可以在 部分中添加对 web.config 的程序集引用,如下所示:

        <compilation debug="true">
          <assemblies>
             <add assembly="Aspose.Cells, Version=4.1.2.0, Culture=neutral,  PublicKeyToken=9a40d5a4b59e5256"/>
          </assemblies>
        </compilation>
        

        我不完全确定这会起作用,它可能需要在 下的 节点中对应 web.config 条目。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-07-19
          • 1970-01-01
          • 2013-11-30
          • 1970-01-01
          • 1970-01-01
          • 2018-08-23
          相关资源
          最近更新 更多