来自bin文件夹ASP.NET负载托管的DLL [英] ASP.NET Load unmanaged dll from bin folder

查看:180
本文介绍了来自bin文件夹ASP.NET负载托管的DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问:我在ASP.NET中使用嵌入式Firebird数据库

Question: I use an embedded Firebird database in ASP.NET.

现在,火鸟大约有本地的dll一个.NET包装。

Now, Firebird has a .NET wrapper around native dlls.

现在的问题是,与ASP.NET编译和执行的过程中,得到的DLL影像复制到临时文件夹。遗憾的是,只有在.NET的DLL,而不是本地的dll。

The problem is, with the ASP.NET compilation and execution process, the dlls get shadow copied to a temporary folder. Unfortunately, only the .NET dlls, and not the native dll.

请参阅 http://msdn.microsoft.com/en-us/library /ms366723.aspx 获取详细信息。

现在,这使得有必要将非托管的dll地方到system32目录下(或在PATH环境变量的任何其他目录)。

Now, this makes it necessary to put the unmanaged dll somewhere into the system32 directory (or any other directory in the path environment variable).

现在,我想换个包装/机DLL(开源),所以它加载的DLL如果他们也只是在bin文件夹。

Now, I want to change the wrapper/native dll (opensource), so it loads the dlls also if they are only in the bin folder.

现在,我的问题是,我怎么能在.NET中,从绝对路径加载一个托管的DLL?
绝对路径是在运行时决定的,而不是在编译时...

Now, my problem is, how can I, in .NET, load an unmanaged dll from an absolute path ?
The absolute path is determined at runtime, not at compile-time...

推荐答案

嵌入到您的组装机DLL。

Embed the native dll in your assembly.

的Application_Start(),检查 Environment.CurrentDirectory Assembly.GetExecutingAssembly() .Location 或任何实际指向的,你想要的,该文件,如果没有present,流出来,通过 Assembly.GetManifestResourceStream()

On Application_Start(), check Environment.CurrentDirectory or Assembly.GetExecutingAssembly().Location or whatever actually points to where you want to be, for the file and if not present, stream it out via Assembly.GetManifestResourceStream().

请注意,这可能会导致一个AppDomain回收,例如:重新启动您的应用程序,但因为你是刚刚开始起来,这是一个非问题。

Note, that this will likely cause an appdomain recycle, e.g. restarting your app, but since you are just starting it up, it is a non-issue.

不知道为什么你要绝对路径,epecially非托管DLL。您将得到更好的里程较少的痛苦,如果你只是找到非托管的DLL在同一个目录中被调用它的程序集。

Not sure why you want an absolute path, epecially for an unmanaged dll. You will get better mileage with less pain if you simply locate the unmanaged dll in the same directory as the assembly that is calling it.

这篇关于来自bin文件夹ASP.NET负载托管的DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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