IIS无法加载依赖DLL

时间:2013-06-12 10:21:36

标签: iis dll environment-variables

我使用C ++ / CLI创建了一个DLL,以便包装一些非托管C ++代码(例如boost)。只要我

,这项工作就很好了
  • 将所有相关DLL放入一个文件夹中
  • 通过%PATH%环境将该文件夹传播到IIS(需要重新启动系统)。

但Microsoft指出,将所有依赖项放在应用程序路径下的bin目录中应该足够了。最后说出以下内容:

Server Error in '/' Application.

Could not load file or assembly 'NETLibd.DLL' or one of its dependencies. The specified module could not be found.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'NETLibd.DLL' or one of its dependencies. The specified module could not be found.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[FileNotFoundException: Could not load file or assembly 'NETLibd.DLL' or one of its dependencies. The specified module could not be found.]
   System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
   System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +39
   System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks) +132
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +144
   System.Reflection.Assembly.Load(String assemblyString) +28
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +46

[ConfigurationErrorsException: Could not load file or assembly 'NETLibd.DLL' or one of its dependencies. The specified module could not be found.]
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +618
   System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +209
   System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +178
   System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +94
   System.Web.Compilation.BuildManager.CallPreStartInitMethods() +332
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +677

[HttpException (0x80004005): Could not load file or assembly 'NETLibd.DLL' or one of its dependencies. The specified module could not be found.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9090988
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
   System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +258

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272

我查看了Microsoftothers的建议,并相应地调整了web.config。他们都没有为我做好准备。

   <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <probing privatePath="/bin;bin/modules;/modules;\modules;bin\modules" />
            <dependentAssembly>
                <assemblyIdentity name="boost_chrono-vc100-mt-gd-1_52" publicKeyToken="0" culture="neutral" />
                <codeBase version="0.0.0.0" href="file:///C:/app/bin/modules/boost_chrono-vc100-mt-gd-1_52.dll" />
            </dependentAssembly>
    </assemblyBinding>
   </runtime>

是否有可能告诉IIS仅针对此应用程序的特定路径,例如通过web.config。我认为在生产系统上,通过%PATH%系统范围内提供所有这些库是不明智的。至少有趣的是找不到哪个DLL(我知道依赖walker,但由于所有DLL都在同一个目录中,所以不会抱怨任何丢失的文件)。

1 个答案:

答案 0 :(得分:0)

我想从C ++ DLL执行函数,该函数驻留在&#39; bin&#39;的子文件夹中,在IIS上我必须使用ADMIN权限将我的Web应用程序添加到AppPool。之后,它加载没有错误,在普通的AppPool中它不会正确加载(执行)。