Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.net calling C# layer calling Managed C++ calling Native C++

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:

  1. 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.

like image 979
UshaP Avatar asked Feb 24 '23 09:02

UshaP


1 Answers

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.

like image 187
Justin Avatar answered Mar 07 '23 19:03

Justin