C# IIS 7.0应用程序加载事件

C# IIS 7.0应用程序加载事件,c#,.net,wcf,rest,iis,C#,.net,Wcf,Rest,Iis,我在.NET 4.0中开发了一个基于WCF Rest的服务,它依赖于win32 dll(在不同的路径上)。Win32 dll与C++/CLI dll静态链接,并使用spring.net进行依赖项注入。 因为我是通过spring创建对象的,所以这些对象是在IIS加载应用程序时创建的。如果win32 dll的路径不正确,IIS将发出错误消息,说明无法加载C++/CLI dll或其依赖项之一 Exception type: ConfigurationErrorsException Exceptio

我在.NET 4.0中开发了一个基于WCF Rest的服务,它依赖于win32 dll(在不同的路径上)。Win32 dll与C++/CLI dll静态链接,并使用spring.net进行依赖项注入。 因为我是通过spring创建对象的,所以这些对象是在IIS加载应用程序时创建的。如果win32 dll的路径不正确,IIS将发出错误消息,说明无法加载C++/CLI dll或其依赖项之一

Exception type: ConfigurationErrorsException 
Exception message: Could not load file or assembly 'Services.DLL' or one of its dependencies. The specified module could not be found.
at System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective)
at System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory()
at System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai)
at System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig)
at System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies()
at System.Web.Compilation.BuildManager.CallPreStartInitMethods()
at System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException)
我尝试使用设置IIS应用程序的路径

Environment.SetEnvironmentVariable("PATH", "path_to_win32_dll;%PATH%", EnvironmentVariableTarget.Process) 
在Global.asax中:Application_Start(objectsender,EventArgs e),但由于应用程序本身没有加载,因此不会执行Application_Start。 是否有任何方法可以在加载任何dll之前在IIS应用程序中获取事件,或者在宿主环境中获取挂钩,以便在加载dll之前设置路径。
在.Net 4.0中,是否有在加载dll时创建的缓存?有办法清除它们吗?

您必须将本机dll放到%windir%\system32,或者学习如何将本机dll与您的C++/CLI合并。它不能与C++/CLI合并,因为它还与其他WIN32应用程序一起使用。