Third party dll can't find its dependencies in ASP.NET MVC project

后端 未结 3 670
难免孤独
难免孤独 2021-01-15 01:40

I use third party library in my project. Call it like MainLibNET.dll. I added this library in References of my project. This dll has dependencies w

相关标签:
3条回答
  • 2021-01-15 01:58

    Managed assemblies get shadow copied by ASP.NET. This process doesn't include unmanaged libraries which explains why they cannot be resolved. One possibility is to add those native libraries into the c:\windows\System32\Inetsrv folder. Another possibility is to put them into a folder which is part of the PATH environment variable.

    0 讨论(0)
  • 2021-01-15 02:12

    I followed option 2a (1c) as mentioned in this blog, and it works beautifully.

    1. In Visual Studio, right click the project and Add Existing Items for each native DLL

    2. Right click each added DLL and choose Properties; set Build Action=Content and Copy to Output Directory = Copy Always. This will cause VS to copy files to bin directory.

    3. Add following code to Global.asax, so ASP.NET will know where to look for the native DLLs.

    .

    protected void Application_Start(object sender, EventArgs e)
    {
        String _path = String.Concat(System.Environment.GetEnvironmentVariable("PATH"), ";", System.AppDomain.CurrentDomain.RelativeSearchPath);
        System.Environment.SetEnvironmentVariable("PATH", _path, EnvironmentVariableTarget.Process);
    }
    
    0 讨论(0)
  • 2021-01-15 02:13

    ASP.NET uses shadow copying, which:

    enables assemblies that are used in an application domain to be updated without unloading the application domain.

    You can add the following item to your Web.config file to disable this sandboxing feature:

    <configuration>
    ...
      <system.web>
       ...
          <hostingEnvironment shadowCopyBinAssemblies="false" />
      </system.web>
    
    

    This should allow you to load native DLL as you would for a .NET console application.

    0 讨论(0)
提交回复
热议问题