使用Web服务时出现问题(正在使用Manged dll)

问题描述:

我正在开发 Web服务以使用托管的C ++ dll (C ++/CLI dll).
该托管的C ++ dll反过来利用未管理的(本机)C ++ dll [通过LoadLibrary ....]

我已将此管理的dll添加到我的Web服务中作为参考(以及所有它引用的程序集).现在,当我尝试在ASP或C#客户端中使用此Web服务时,我得到了:

*******错误日志启动*********

找不到指定的模块.(来自HRESULT的异常:0x8007007E)"
说明:执行当前Web请求期间发生未处理的异常.请查看堆栈跟踪,以获取有关错误及其在代码中起源的更多信息.

异常详细信息:System.IO.FileNotFoundException:找不到指定的模块. (来自HRESULT的异常:0x8007007E)

源错误:

当前Web请求的执行期间生成了未处理的异常.可以使用下面的异常堆栈跟踪来标识有关异常的来源和位置的信息.

堆栈跟踪:

[FileNotFoundException:找不到指定的模块. (来自HRESULT的异常:0x8007007E)]
System.Reflection.Assembly._nLoad(AssemblyName文件名,字符串codeBase,证据AssemblySecurity,程序集locationHint,StackCrawlMark& stackMark,布尔型throwOnFileNotFound,布尔型用于自省)+0
System.Reflection.Assembly.nLoad(AssemblyName文件名,字符串codeBase,证据assemblySecurity,程序集locationHint,StackCrawlMark& stackMark,布尔throwOnFileNotFound,布尔forIntrospection)+43
System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef,证据assemblySecurity,StackCrawlMark& stackMark,用于自省的布尔值)+127
System.Reflection.Assembly.InternalLoad(字符串assemblyString,证据assemblySecurity,StackCrawlMark& stackMark,用于自省的布尔值)+142
System.Reflection.Assembly.Load(String assemblyString)+28
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(字符串assemblyName,布尔型starDirective)+46

...................

*******错误日志结束*********

但是我可以在C#控制台应用程序中引用相同的托管dll(从与webservice相同的位置),这证明所有必需的依赖项都可用.
任何人都可以给我提示/方向来解决此问题.

在Web服务中调用托管dll(利用非托管dll)时会发生什么特别的事情?

I am developing a Webservice for consuming a Managed C++ dll (C++/CLI dll).
This managed C++ dll is in turn utilizing unmanged (native) C++ dlls [via LoadLibrary ....]

I have added this manged dll to my webservice as reference (and also all it''s refered assemblies). Now when I try to use this webservice in ASP or C# client I am getting :

******* Error log start *********

"The specified module could not be found. (Exception from HRESULT: 0x8007007E)"
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: The specified module could not be found. (Exception from HRESULT: 0x8007007E)

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: The specified module could not be found. (Exception from HRESULT: 0x8007007E)]
System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +0
System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +43
System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +127
System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +142
System.Reflection.Assembly.Load(String assemblyString) +28
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +46

...................

******* Error log end *********

But the same manged dll I could able to refer (from the same location as I refered from webservice) in an C# console application, which proves that all the required dependencies are available.

Can any one please give me hints/directions to solve this issue.

Any thing peculiar in invoking manged dlls (utilizing unmanaged dlls) in webservice ?

该错误表示它的含义.文件丢失.因此,您尚未将其复制到服务器上,或者该文件在那里,但是对ASP.NET用户不可见.我会怀疑是后者,它是Web服务在其下运行的ASP.NET用户的权限问题.
The error means what it says. A file is missing. Therefore you have not copied it to the server, or the file is there, but not visible to the ASP.NET user. I would suspect the latter, that it''s a permissions problem with the ASP.NET user that the web service runs under.


正如我已经说过的,我的托管dll(该Web服务是包装)正在使用本机dll,这会导致问题.

在确定了准确的(本机)dll之后,我尝试延迟加载它(只是为了查看是否与加载有关),并且它起作用了.

然后,我尝试将这个dll保留在system32文件夹中,并删除了延迟加载,然后它也起作用了-所以我教导说该dll很好,但是网络服务无法找到它[它可以与其他MANAGED一起使用dlls ].因此,即使我将其放置在正确的路径中,它也只会给出"System.IO.FileNotFoundException".

最后,我在"Path"环境变量下添加了本机dll的路径[并还原了之前尝试过的所有步骤],并且可以正常工作.

我目前正在坚持这种解决方法,并欢迎对此方法的任何建议/利弊


另外,不要忘记仅尝试使用RELEASE构建,因为DEBUG构建可能会失败.
As I already stated that my managed dll (which the webservice is wrapping) is using a native dll and this is causing the problem.

After identifying the exact (native) dll, I tried to delay load it (just to see if any thing to do with loading) and it worked.

Then I tried to keep this dll in system32 folder and removed delay loading, then also it worked - so I taught that the dll is fine, but webservice is not able to locate it [while it can able to do with other MANAGED dlls]. So only it is giving ''System.IO.FileNotFoundException'', even though I placed it in proper path.

Finally I added the path of my native dlls under ''Path'' environmental variable [and reverted all the previous tried steps] and it worked.

I am currently holding to this work-around and welcome any suggestions / pro and cons of this approach


Also do not forget to try with RELEASE build only, as DEBUG build may fail.