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 (24)

  1. ghuckabone says:

    How does one link statically?

    -gary

  2. EldarM1 says:

    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!

  3. Senthil Balu says:

    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

  4. Tony Antonucci says:

    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.

  5. Paul says:

    See http://www.microsoft.com/downloads/details.aspx?familyid=32BC1BEE-A3F9-4C13-9C99-220B62A191EE&displaylang=en

    These are the required runtime components to run apps develpoed with VS2005.  You either need to include this in your distribution, or use VC++6.

  6. Terrence says:

    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.

  7. Brent says:

    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.

  8. Erik Miller says:

    I took my Win32 dll and in the section where it asks you how to link to MFC, I put in "Use Standard Windows Libraries" and everything works fine now.  The DLL is 10x larger but disk space a dime a GB so who cares right?

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

  10. EldarM1 says:

    SysInternals FileMon was pretty good at that. Also there is a tool in Visual Studio for that, but it did not worked real time, rather trying to model the execution.

  11. BrockG says:

    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.

  12. nitin says:

    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

  13. EldarM1 says:

    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…

  14. Ryan Taylor says:

    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

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

  16. shravan says:

    in most of the cases u need following folders:

    The folders you need for that are

    Microsoft.VC80.CRT

    Microsoft.VC80.DebugCRT

    Microsoft.VC80.DebugMFC

    Microsoft.VC80.MFC

    Microsoft.VC80.MFCLOC

    Microsoft.VC80.OPENMP

    as well u sud use depends.exe(C:Program FilesMicrosoft Visual Studio 8Common7ToolsBin) and check the system log for the required file missing.

    but if ur using release mode then leave the debug folders of Microsoft.VC80 .

    i solved my problem but its a royal pain in ass 🙂

  17. Dan says:

    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

  18. tushar says:

    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

  19. B says:

    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

  20. Krutarth P. Patel says:

    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

  21. Ariel Gonzalez says:

    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.

  22. Hans Luh says:

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

Skip to main content