Mixed mode assembly loading in asp.net

I have an asp.net webservice that references a mixed mode dll. The native dll's that the mixed mode assembly reference are in a directory that is added to SYSTEM PATH.

I want to remove the native dll's directory from the SYSTEM PATH, so I copied all the native dll's to webservice's bin directory, but I get file not found exception.

Does asp.net not look in webservice's bin directory for native dlls? Is there a way to dynamically set the SYSTEM PATH? How can I get this to work.


If anyone is facing a similar situation, this is what I did to be able to load a mixed mode assembly from a location not in these locations:

  • The directory from which the application loaded. In the case of ASP.Net, this will resolve to %windir%Microsoft.NetFrameworkv### or %windir%system32inetsrv for IIS 6.
  • The current directory. In the case of ASP.Net, this will resolve to %windir%System32inetsrv for IIS 6. If using the built-in web server, this resolves to a path under C:Program FilesMicrosoft Visual Studio 8.
  • The Windows system directory. Use the GetSystemDirectory function to get the path of this directory.
  • The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
  • The directories that are listed in the PATH environment variable.
  • I set the native dlls on the mixed mode assembly to be delay loaded. Then I followed option 2b from http://blogs.msdn.com/b/jorman/archive/2007/08/31/loading-c-assemblies-in-asp-net.aspx

    I just had to make one minor tweak to the option 2b. It says to update "Application_Start" method in Global.asax, but I had to update the "Application_BeginRequest" method to get this to work with my webservice.

    链接地址: http://www.djcxy.com/p/44540.html

    上一篇: IIS ASP.NET MVC和dllimport调用会锁定该文件,以防未来部署

    下一篇: 在asp.net中加载混合模式程序集