Поделиться через


0x800736B1: Calling C++ code from ASP.Net (from .aspx pages or .asmx webservices)

So, you have (or have to write) ASP.Net page or webservice, which should call native C++. Generally, it’s just extra work, but sometimes there is no other way, at least, no easier way.

Overall that’s fairly easy – use COM or P/Invoce, that’s it. However, sometimes you do so, and it does not work no matter what. A pretty common case is HRESULT code 0x800736B1 with a full message like "Unable to load DLL exception. This application has failed to start because the application configuration is incorrect. Reinstalling application may fix this problem." Very often case. And very puzzling. And not very well documented.

So now a big hint: that usually does not mean that your DLL is not found (although that’s possible), it usually means that your DLL depends on other DLLs that are missing. It usually happens when you develop on one machine, and deploy/run on another, especially if it has a different version of Windows or misses Visual Studio. Just check that everything needs is on the machine or link statically (although that will increase the size of your DLL).

P.S. Oh, I was just told that this is not the only thing that could go wrong... Sorry if I was not clear enough. What I wrote above, is something happening easily and likely, while overall list of what can go wrong is HUGE:

- permissions on DLL(s)
- code security
- wrong .config file
- wrong version of .Net
- P/Invoke problems/signature matches/encoding/preserving-not preserving signature...
- actual file location
- not being in a right place or Path if DLL is specified without a full path
- more..

Comments

  • Anonymous
    September 15, 2006
    How does one link statically?
    -gary

  • Anonymous
    September 18, 2006
    Statically? Native .lib files will not link with managed assemblies. If you mean DLLImport, yes, there is such a problem because ASP.NET code is compiled into some other place, and nobody wants to put the binaries into System32. One option is to add a special directory to path -- to the end of the list -- and put there you native DLLs. I used another way -- preloading native DLLs with LoadLibrary() -- this works too. As long as the DLL already loaded, the system does not look for it on the disk. But in this case, you need to know the path to your DLL in ASP.Net page to load it.

    Actually, I should write about it with examples. Thanks for the idea!

  • Anonymous
    January 11, 2007
    We create a C++ managed DLL using desktop with VS2005 with SP1. when i try to use the DLL in the desktop without SP1(service pack 1). I am ending with "The application is "the application has failed to start because the application confiquration is incorrect. etc.. (Exception from HRESULT: 0x800736B1)"]. ". Is there any way to solve the problem. whats the reason for this problem

  • Anonymous
    January 18, 2007
    I have exactly the same problem, does anyone have a solution? --I build a DLL that is sent to thousands of users. They do not have Visual Studio, this all worked fine until SP1.

  • Anonymous
    January 29, 2007
    The comment has been removed

  • Anonymous
    March 06, 2007
    The available VC+ redist only installs the .42 version of the C Runtime files.  This does not resolve the issue when you compile using VS SP1 which references the .762 version of the C Runtime files.  We tried everything from including the folders in our install directory to updating the path and system32, but nothing worked.  Even Depends showed that everything was available, but the web service would not run on the target machine. We resolved this issue by compiling using a machine without VS SP1 installed.  Not ideal, of course, but allows us to keep going.

  • Anonymous
    April 06, 2007
    This is also true for windows services and winforms apps developed in .NET, not just web apps/services. I've been struggling with this issue for two days now. I 've got my service running on my local XP Pro machine, but deploying to Server 2003 is rough. Not to mention it's the 64-bit edition.

  • Anonymous
    April 27, 2007
    The comment has been removed

  • Anonymous
    May 12, 2007
    Hi there, THanks for the insightful article. I am trying to get a very old application set up in Vista and I am getting the "was loaded but the call to DLLRegisterServer failed with error code 0x80040154" error. After googleing for a bit I found our article. What might be a way for me to find out the dependencies of a dll file for an application that I can't install? Any assistance would be great. Sherif a t sherifmansour dot com

  • Anonymous
    June 14, 2007
    The comment has been removed

  • Anonymous
    June 26, 2007
    I was having the same error when distributing an .exe I built with VS 2005.  I found it was solved by including the redist files found in C:Program FilesMicrosoft Visual Studio 8VCredistx86 If I distributed the folders: Microsoft.V80.CRT and Microsoft.V80.MFC and placed them in the same directory as the application, the configuration error went away.  Hope this helps.

  • Anonymous
    June 27, 2007
    Hello friends I am facing lotof problems , registering dlls and ocx in vista, even after setting the protective mode off. I use a .Net application that invokes a dll on the client machine that further registers certain controls after transferring them from server. I have checked rights in TYPELIB and CLSID both , through my code, and there is ALLACCESS.Still the registerserver fails to run

  • Anonymous
    July 24, 2007
    BrockG: With .exe it's a natural problem. You can replace DLL with static library in the project C++ / Code Generation options, and then you won't have to copy DLLs from Visual Studio. Although your files will grow for about 500K in size. Nitin: It's really hard to say what's wrong when symtoms are just " a lot of problems". .Net app may run under a different identity, DLL may have bugs in the way ot registers the coponents, comonents may not match what this DLL tries to register or have their own bugs, if the do part of the self-reg themselves...

  • Anonymous
    August 30, 2007
    Hi, I was facing the same problem yesterday and we resolved it.  Basically we have a C# program that includes a C++ project.  Like others have mentioned above, when we build the solution it compiles the C++ project using .62.  Sure enough, our clients only have .42.   Microsoft recently published service pack for the C++ redistributable package.  It is a 2.6MB download.  When we installed in our clients machine, everything worked perfectly. Here is the link to the download on Microsoft's website: http://www.microsoft.com/downloads/details.aspx?familyid=200B2FD9-AE1A-4A14-984D-389C36F85647&displaylang=en Also, I came to this solution via:http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1240807&SiteID=1 Good luck, Ryan

  • Anonymous
    October 17, 2007
    PingBack from http://archworx.wordpress.com/2007/10/17/resolution-to-exception-from-hresult-0x800736b1/

  • Anonymous
    April 24, 2008
    I have a problem deploying a managed DLL to a new machine.  I am running .NET Visual Studio 2005 (professional ed.). When in debug mode, I get a FileLoadException, and in release mode I get a BadImageFormatException.  The dll actually does load but instantly unloads itself.  I believe that the assembly is loading but cannot instantiate any of the objects that are contained in the dll and the exceptions above are thrown depending on Debug/release mode.  I can step to the code right up until I try to instantiate an object.  When I step in, I get the load/unload trace to the output window followed by the exception trace.   Any help would be greatly appreciated.  I tried uninst/reinst, and copied dlls from other machines, etc.  and have spent nearly a week on this issue.  Thanks,  Chris

  • Anonymous
    June 20, 2008
    The comment has been removed

  • Anonymous
    September 09, 2008
    Dear all, I have a vc++ dll that i am using in my web service C# solution that is deployed in IIS. I am getting the same sort of problem as described above. Would anoyone please be able to let us know how you solved the problem? I installed the VC++ distributable that is 2mb and provided by MS but that did not solve the problem. Any other suggestions? Sincerely Dan

  • Anonymous
    September 26, 2008
    Hi , I am getting this error when i transfer my asp.net website from one server to other please help me I never done such work before I tried to find out reason behind it but not getting solution please provide solution ASAP

  • Anonymous
    January 21, 2009
    PingBack from http://www.keyongtech.com/672053-dll-wont-run-on-user

  • Anonymous
    August 28, 2009
    I had to add the following merge modules to my Setup Project to eliminate that error: C:Program FilesCommon FilesMerge ModulesMicrosoft_VC90_DebugCRT_x86.msm C:Program FilesCommon FilesMerge Modulespolicy_9_0_Microsoft_VC90_DebugCRT_x86.msm

  • Anonymous
    September 03, 2009
    On error :


This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem. (Exception from HRESULT: 0x800736B1)

install Microsoft Visual C++ 2005 Redistributable Package (x86) Download link : http://www.microsoft.com/downloads/details.aspx?familyid=32BC1BEE-A3F9-4C13-9C99-220B62A191EE&displaylang=en Will helps you. Keep Smiling

  • Anonymous
    September 21, 2009
    Hi everyone I had this error too. After trying several solutions which none worked by itself, I found where exactly the problem resides. Well it seems that those who develop in VS with SP1 and then run the app in a pc or publish the website to a server without VS on it got this error. The solution is yes you need to have installed VC ++  redistributable package SP1 but you also have to build the C++ project that generates the problematic dll in Release mode (not debug). Doing this will solve all your problems.

  • Anonymous
    April 02, 2010
    Finally.  It is the solution for my problem. "After trying several solutions which none worked by itself, I found where exactly the problem resides. Well it seems that those who develop in VS with SP1 and then run the app in a pc or publish the website to a server without VS on it got this error. The solution is yes you need to have installed VC ++  redistributable package SP1 but you also have to build the C++ project that generates the problematic dll in Release mode (not debug). Doing this will solve all your problems."