C # Call the VC ++. Net Library Assembly DLL

Source: Internet
Author: User
Cocould not load file or assembly '...' or one of its Dependencies. the application fails to start because the application configuration is incorrect...

The two projects are. the C # And C ++ and C ++ projects under net2005 use C ++/CLI to encapsulate several functional functions and load and use encapsulation classes in the C # project. The exception dialog box appears when running normally locally but is released to other machines: "cocould not load file or assembly '...... 'or one of its dependencies. the application cannot be started because the application configuration is incorrect. Re-installing the application may correct this problem. (Exception from hresult: 0x800736b1 )".

This error seems to be a problem with the c ++ dll library. Because the hybrid mode is used to compile the hosted DLL, the DLL will use the unmanaged CRT (C Run-Time) Library. If these runtime components are not installed on the machine, an error similar to hresult: 0x8007 is generated. The simplest method is to download and install Microsoft Visual C ++ 2005 redistributable package (x86) to obtain the msvcr80.dll and msvcm80.dll required for code running; you can also find the MSM file containing the CRT in the Program Files \ common files \ merge modules directory on the system disk, and add these files to your installer to achieve the same effect; if C ++ generates executable files instead of DLL files, you can copy the required DLL files to the application directory according to Microsoft's instructions. For more detailed analysis instructions, see bootstrapper for the VC ++ 2005 redists (with MSI 3.1 ).

Note that if you use DEBUG configuration when compiling the C ++ hosted assembly, the generated dll must call the debug version corresponding to the CRT (msvcr80d. DLL and msvcm80d. DLL) instead of the files in the above redistributable package. In this way, even if you use any method to install those Runtime library files, the error exception dialog box will still be displayed. To understand whether the generated DLL is debug or release, you can use a text editor to open the DLL file and find the following similar content (usually at the end of the file ):

View plaincopy to clipboardprint?
  1. <Assembly xmlns = "urn: Schemas-Microsoft-com: ASM. V1"
  2. Manifestversion = "1.0">
  3. <Dependency>
  4. <Dependentassembly>
  5. <Assemblyidentity type = "Win32"
  6. Name = "Microsoft. vc80.debugcrt"
  7. Version = "8.0.50608.0"
  8. Processorarchitecture = "x86"
  9. Publickeytoken = "1fc8b3b9a1e18e3b">
  10. </Assemblyidentity>
  11. </Dependentassembly>
  12. </Dependency>
  13. </Assembly>

<Assembly xmlns = "urn: Schemas-Microsoft-com: ASM. v1 "<br/> manifestversion =" 1.0 "> <br/> <dependency> <br/> <dependentassembly> <br/> <assemblyidentity type =" Win32 "<br/> name = "Microsoft. vc80.debugcrt "<br/> Version =" 8.0.50608.0 "<br/> processorarchitecture =" x86 "<br/> publickeytoken =" Courier "> <br/> </assemblyidentity> <br /> </dependentassembly> <br/> </dependency> <br/> </Assembly>

 

If you seeMicrosoft. vc80.debugcrtIt indicates that the DLL link is the debug version of CRT.Microsoft. vc80.crtLink to the redistribution version. When I am in. when the net2005 ide generates C # EXE and C ++ DLL through batch generation, if the current active solution configuration is debug, the C # project's release output directory copies the C ++ DLL debug version file instead of the release version! Therefore, it is quite necessary to confirm the version of the corresponding file after the release is generated.

Another possibility is that if your hard disk partition is in FAT32 format, when compiling C ++ DLL, vs.net may fail to correct manifest information due to timestamp calculation errors (basically the xml configuration information mentioned above) writing to the DLL results in a loading error because the correct dependency information is not obtained during the program running. So if the above operation still cannot solve the error, choose "properties"> "configuration properties"> "configuration tools"> "general" and set "use FAT32 solution" to "yes ".

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.