问题
My project structure is as follow:
ASP.NET calling C# layer calling Managed C++ calling Native C++
(i'm trying to avoid using interop so this is why the managed c++ layer)
I wrote unit test that test the C# layer and it works fine.
When I try to run the asp.net page i'm getting: "Could not load file or assembly..."
error.
I figured out that when i copy paste the Native C++ dll to "Temporary ASP.NET Files" (to the corresponding folder) the site works.
It seems that the Managed C++ code can find the Native C++ code only if it resides in the same folder - obviously I can't have my Native dll in the temp files.
Is there a way to set the Native in a global place(doesn't work with System32)?
Thanks for you comments.
It boils down to one option:
- It is security issue
i set up the server it self with the code and it runs under the cassini, but when i publish it(to run under iis7) i'm getting "Could not load file or assembly ...." i'm running IIS7 with ApplicationPoolIdentity , .net 4 Integrated Thanks a lot, Pini.
回答1:
Well technically using Managed C++ in this way is a form of Interop between native / managed code, the commonly used alternatives being COM and P/Invoke. This is purely a terminology thing however, you would get the same issue using P/Invoke.
This blog article Loading C++ Assemblies in ASP.Net might help you out - In short you need to either:
- Set the
%PATH%
environment variable before the Managed C++ assembly attempts to load your native C++ dll. - Use the
DllImport
attribute to set the dll path (not applicable in your case as you aren't using P/Invoke) - Manually load the C++ dll yourself (e.g. with
LoadLibrary
) before the Managed C++ assembly attempts to load your native C++ dll.
I suspect that installing your dll to Win SxS would also work, but I don't know enough about how this works to be sure.
回答2:
You can set your path variable?
You set it by going to the Properties of "My computer"/"Computer (Windows-PauseBreak) and then clicking advanced settings. Click advanced. Environment variables. Modify "Path" under system variables as needed.
回答3:
I had to flip a bool in the ApplicationPoolIdentity. One of the filed in the properties says "enable 32bit" and that did the trick :) the default is False My server is 64bit and i build my native with 32bit.
来源:https://stackoverflow.com/questions/5806144/asp-net-calling-c-sharp-layer-calling-managed-c-calling-native-c