如何加载超出了我的web应用程序的bin目录汇编 [英] How to load an assembly outside my web app's bin directory
本文介绍了如何加载超出了我的web应用程序的bin目录汇编的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从比bin文件夹以外的位置加载我的程序集。
I want to load my assemblies from a location other than the bin folder.
我怎样才能做到这一点?
How can I accomplish this ?
感谢您
推荐答案
请注意:
我的previous答案是不正确的。山姆持有人的假设听起来似是而非,所以我写了一些测试,以确认。
My previous answer was incorrect. Sam Holder's supposition sounded plausible so I wrote some tests to confirm.
考虑它证实。
要测试,添加到项目或DLL并设置'复制本地假的参考。请确保您显示所有文件,并删除bin目录,或者你将有一个挥之不去的dll在那里。
To test, add a reference to a project or dll and set 'Copy Local' to false. Make sure you 'show all files' and delete the bin dir or you are going to have a lingering dll in there.
的Global.asax
namespace WebApplication1
{
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.AssemblyResolve += new ResolveEventHandler(currentDomain_AssemblyResolve);
}
System.Reflection.Assembly currentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
if (args.Name == "ClassLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")
{
String assemblyPath = @"C:\Projects\StackOverflowAnswers\WebApplication1\ClassLibrary1\bin\Debug\ClassLibrary1.dll";
Assembly assembly = Assembly.LoadFrom(assemblyPath);
return assembly;
}
return null;
}
.....
该任择议定书也许应该给我一个给予好评,但萨姆应该得到的检查。
The OP should perhaps give me an upvote but Sam should get the check.
这篇关于如何加载超出了我的web应用程序的bin目录汇编的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文