ASP.NET应用程序对以编程方式加载的程序集中的程序集的引用 [英] ASP.NET application reference to assembly in programmatically loaded assembly

查看:68
本文介绍了ASP.NET应用程序对以编程方式加载的程序集中的程序集的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My ASP.NET application loads an assembly and creates a class instance from an object within it. The assembly itself has a reference to a dll called "Aspose.Cells.dll" which it can access without any problems and is located on the same path as the assembly file itself. However, when I make a method call to one of its methods I get this error:

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

Could not load file or assembly 'Aspose.Cells, Version=4.1.2.0, Culture=neutral, PublicKeyToken=9a40d5a4b59e5256' or one of its dependencies.

我认为我还需要使我的ASP.NET应用程序也引用此DLL,但到目前为止,我尝试过的所有操作都失败了.加载的程序集DLL不在Web应用程序的根目录中,我希望它不必一定是这样.

I figure that I need to make my ASP.NET application reference this DLL as well but everything I've tried so far has failed. The assembly DLL which is loaded is not located within the root of the web application and I'm hoping that it doesn't have to be.

我可以这样加载程序集:

I can load the assembly like this:

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

但是我不能这样使用它:

But I can not use it like this:

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,因为我希望它可以作为插件系统工作,通过更改配置文件中程序集的路径即可轻松替换程序集,而不必手动将文件复制到主项目中.

I forgot to mention that I cannot copy the assemblies to the bin folder or the GAC because I want it to work as a plugin system where assemblies can be replaced easily by changing the path to assemblies in a configuration file and not having to manually copy files into the main project.

但是,AssemblyResolve事件似乎很有趣,我将在以后尝试.

However, the AssemblyResolve event seems interesting and I will give it a try later.

推荐答案

有几种方法可以做到这一点. Microsoft知识库文章中介绍了一种方法 "如何在运行时加载位于应用程序的bin文件夹以外的文件夹中的程序集".它提供了一个很好的逐步方法.

There are a few ways to do this. One way is described in the Microsoft Knowledge Base article "How to load an assembly at runtime that is located in a folder that is not the bin folder of the application". It provides a pretty good step-by-step method of how to do this.

这篇关于ASP.NET应用程序对以编程方式加载的程序集中的程序集的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆