我用 C++/CLI 创建了一个 DLL,以便包装一些非托管 C++ 代码(例如 boost)。只要我,这项工作就很好
- 将所有依赖的 DLL 放在一个文件夹中,然后
- 通过环境将该文件夹传播
%PATH%
到 IIS(需要重新启动系统)。
bin
但是,Microsoft 声明将所有依赖项放在应用程序路径下的目录中就足够了。这最终会说以下内容:
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
我已经查看了Microsoft和其他人的建议并进行了相应的调整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都在同一个目录中,它不会抱怨任何丢失的文件)。